Topic: How to get a post's comments using the API

Posted under e621 Tools and Applications

I am currently working application that uses e621's API, and I am trying to fetch a post's comments, but the API Documentation does not state how to fetch comments. I've tried using https://e621.net/comments.json but that does not return comments but seemingly random posts. I've also tried https://e621.net/posts/[post_id]/comments.json and that returns a piece of html, which is the comment section of the post, but it doesn't seem like that is supposed to happen. Does anyone know how to do it properly?

kora_viridian said:
That is weird. That might be worth a post in the bug report thread.

It looks like the HTML is wrapped in JSON, and then there's also a list of posts in the JSON after that, but I'm not sure how it selects the posts for that list.

It isn't a bug, it's very much intentional. The default group_by is post, which starts its relation at posts, with comments being pulled in on the visual side. This is utterly useless for api usage, as you've seen.

Minor Technical Details

Posts are returned in the api due to the comments controller using respond_with(@posts), as can be seen here.

Could it be "fixed"? Sure, but it most likely won't be. Should that be officially documented? Definitely. Will it be? Maybe.

If anything, I'd prefer group_by defaulting to comment if the response type is json, as there's really no reason to not group by comments in the context of the api.

  • 1