This page has details for how to interact with comment records through the API.
01 Record field format
[hr]
| Name | Type | Details |
|---|---|---|
| [code]id[/code] | integer | >0 |
| [code]post_id[/code] | integer | >0 |
| [code]body[/code] | string | |
| [code]score[/code] | integer | |
| [code]is_deleted[/code] | boolean | |
| [code]is_sticky[/code] | boolean | |
| [code]do_not_bump_post[/code] | boolean | |
| [code]creator_id[/code] | integer | >0 |
| [code]updater_id[/code] | integer | >0 |
| [code]created_at[/code] | timestamp | |
| [code]updated_at[/code] | timestamp |
02 Associated attributes
[hr]
The following is the list of relations that can be included in the API results (see Help:Common URL Parameters for more info):
| Name | Type | Number | Availability | Details |
|---|---|---|---|---|
| [code]creator[/code] | user | single | required | |
| [code]updater[/code] | user | single | required | |
| [code]post[/code] | post | single | required |
03 Index
[hr]
Returns multiple comment records.
| HTTP Method | GET |
| Base URL | [code]/comments.json[/code] |
| Type | read request |
| Description | The default order is ID descending. |
Note: [code]group_by[/code] as a parameter must be set to [code]comment[/code], or else posts will be returned instead (e.g. [code]group_by=comment[/code]).
Search attributes
Search parameters take the following format (see Help:Common URL Parameters for more info):
[code]
search[FIELD]=VALUE
[/code]
The following are the base fields along with their associated type. Check the syntax pages for all of the available variations.
- Number syntax
- [code]id[/code]
- [code]score[/code]
- [code]created_at[/code]
- [code]updated_at[/code]
- Text syntax
- [code]body[/code]
- Boolean syntax
- [code]is_deleted[/code]
- [code]is_sticky[/code]
- [code]do_not_bump_post[/code]
- Post syntax
- [code]post[/code]
- User syntax
- [code]creator[/code]
- [code]updater[/code]
Special search parameters
The following are additional search fields.
- [code]is_edited[/code] - Whether a comment was edited 5 or more minutes it was created. (see Help:Boolean Syntax)
Search order
Using the search parameter [code]order[/code] with one of the following values changes the order of the results.
- [code]id_asc[/code] - ID ascending.
- [code]created_at[/code] - Created at descending.
- [code]created_at_desc[/code] - Created at descending.
- [code]created_at_asc[/code] - Created at ascending.
- [code]post_id[/code] - Post ID descending.
- [code]post_id_desc[/code] - Post ID descending.
- [code]score[/code] - Post ID descending.
- [code]score_desc[/code] - Post ID descending.
- [code]score_asc[/code] - Post ID ascending.
- [code]updated_at[/code] - Updated at descending.
- [code]updated_at_desc[/code] - Updated at descending.
- [code]updated_at_asc[/code] - Updated at ascending.
- [code]custom[/code] - Ordered by [code]search[id][/code]. (See Help:Common URL Parameters for more info)
04 Show
[hr]
Returns a single comment record.
| HTTP Method | GET |
| Base URL | [code]/comments/$id.json[/code] |
| Type | read request |
| Description | [code]$id[/code] is the comment ID. |
05 Create
[hr]
Creates a single comment record.
| HTTP Method | POST |
| Base URL | [code]/comments.json[/code] |
| Type | write request |
Create parameters
Comment parameters take the following format (see Help:API Write Requests for more info):
[code]
comment[FIELD]=VALUE
[/code]
- Required:
- [code]post_id[/code]
- [code]body[/code]
- Optional
- [code]do_not_bump_post[/code]
- [code]is_sticky[/code] (Moderator+)
06 Update
[hr]
Updates a single comment record.
| HTTP Method | PUT/PATCH |
| Base URL | [code]/comments/$id.json[/code] |
| Type | write request |
| Description | [code]$id[/code] is the comment ID. |
Update parameters
- Optional:
- [code]body[/code]
- [code]is_deleted[/code]
- [code]is_sticky[/code] (Moderator+)
07 Destroy
[hr]
Deletes a single comment record.
| HTTP Method | DELETE |
| Base URL | [code]/comments/$id.json[/code] |
| Type | write request |
| Description | [code]$id[/code] is the comment ID. |
Note: This action can also be accomplished using Update by setting [code]is_deleted[/code] to true.
08 Undelete
[hr]
Undeletes a single comment record.
| HTTP Method | POST |
| Base URL | [code]/comments/$id/undelete.json[/code] |
| Type | write request |
| Description | [code]$id[/code] is the comment ID. |
Note: This action can also be accomplished using Update by setting [code]is_deleted[/code] to false.
09 See also
[hr]
10 External links
[hr]
| Controller | <https://github.com/danbooru/danbooru/blob/master/app/controllers/comments_controller.rb> | |
| Model | <https://github.com/danbooru/danbooru/blob/master/app/models/comment.rb> | |
| Policy | <https://github.com/danbooru/danbooru/blob/master/app/policies/comment_policy.rb> |