Danbooru offers a simple API to make scripting easy. All you need is a way to GET and POST to URLs. The ability to parse XML or JSON responses is nice, but not critical. The simplicity of the API means you can write scripts using JavaScript, Perl, Python, Ruby, even shell languages like bash or tcsh.
Change Log | Posts | Tags | Artists | Comments | Wiki | Notes | Users | Forum | Pools
HTTP defines two request methods: GET and POST. You'll be using these two methods to interact with the Danbooru API. Most API calls that change the state of the database (like creating, updating, or deleting something) require an HTTP POST call. API calls that only retrieve data can typically be done with an HTTP GET call.
In the Danbooru API, a URL is analogous to a function name. You pass in the function parameters as a query string. Here's an extremely simple example: /post/index.xml?limit=1.
The post
part indicates the controller we're working with. In this case it's posts. index
describes the action. Here we're retrieving a list of posts. Finally, the xml
part describes what format we want the response in. You can specify .xml
for XML responses, .json
for JSON responses, and nothing at all for HTML responses.
All API calls that change state will return a single element response (for XML calls). They are formatted like this:
For JSON responses, they'll look like this:
While you can usually determine success or failure based on the response object, you can also figure out what happened based on the HTTP status code. In addition to the standard ones, Danbooru uses some custom status codes in the 4xx and 5xx range.
Status Code | Meaning |
---|---|
200 OK | Request was successful |
403 Forbidden | Access denied |
404 Not Found | Not found |
420 Invalid Record | Record could not be saved |
421 User Throttled | User is throttled, try again later |
422 Locked | The resource is locked and cannot be modified |
423 Already Exists | Resource already exists |
424 Invalid Parameters | The given parameters were invalid |
500 Internal Server Error | Some unknown error occurred on the server |
503 Service Unavailable | Server cannot currently handle the request, try again later |
While you will probably want to work with XML in the majority of cases, if you're writing something in Javascript then the JSON responses may be preferable. They are much faster to parse and there's less code to write to get your data structure:
Some actions may require you to log in. For any action you can always specify two parameters to identify yourself:
Please be aware of the security risks involved in sending your password through an unencrypted channel. Although your password will be hashed, it is still theoretically possible for someone to steal your account by creating a fake cookie based on your hashed password.
The base URL is /post/index.xml.
The base URL is /post/create.xml. There are only two mandatory fields: you need to supply the tags, and you need to supply the file, either through a multipart form or through a source URL.
If the call fails, the following response reasons are possible:
location
will be set, pointing to the (relative) URL of the original post.If the post upload succeeded, you'll get an attribute called location
in the response pointing to the relative URL of your newly uploaded post.
The base URL is /post/update.xml. Only the id
parameter is required. Leave the other parameters blank if you don't want to change them.
You must be logged in to use this action. You must also be the user who uploaded the post (or you must be a moderator).
This action reverts a post to a previous set of tags. The base URL is /post/revert_tags.xml.
This action lets you vote for a post. You can only vote once per post per IP address. The base URL is /post/vote.xml.
1
to vote up and -1
to vote down. All other values will be ignored.If the call did not succeed, the following reasons are possible:
The base URL is /tag/index.xml.
date
, count
, or name
.The base URL is /tag/update.xml.
The base URL is /tag/related.xml.
general
, artist
, copyright
, or character
).The base URL is /artist/index.xml.
date
or name
.The base URL is /artist/create.xml.
The base URL is /artist/update.xml. Only the id parameter is required. The other parameters are optional.
The base URL is /artist/destroy.xml. You must be logged in to delete artists.
The base URL is /comment/show.xml. This retrieves a single comment.
The base URL is /comment/create.xml.
The base url is /comment/destroy.xml. You must be logged in to use this action. You must also be the owner of the comment, or you must be a moderator.
All titles must be exact (but case and whitespace don't matter).
The base URL is /wiki/index.xml. This retrieves a list of every wiki page.
title
, date
.The base URL is /wiki/create.xml.
The base URL is /wiki/update.xml. Potential error reasons: "Page is locked"
The base URL is /wiki/show.xml. Potential error reasons: "artist type"
The base URL is /wiki/destroy.xml. You must be logged in as a moderator to use this action.
The base URL is /wiki/lock.xml. You must be logged in as a moderator to use this action.
The base URL is /wiki/unlock.xml. You must be logged in as a moderator to use this action.
The base URL is /wiki/revert.xml. Potential error reasons: "Page is locked"
The base URL is /wiki/history.xml.
The base URL is /note/index.xml.
The base URL is /note/search.xml.
The base URL is /note/history.xml. You can either specify id
, post_id
, or nothing. Specifying nothing will give you a list of every note verison.
The base URL is /note/revert.xml. Potential error reasons: "Post is locked"
The base URL is /note/update.xml. Notes differ from the other controllers in that the interface for creation and updates is the same. If you supply an id
parameter, then Danbooru will assume you're updating an existing note. Otherwise, it will create a new note. Potential error reasons: "Post is locked"
The base URL is /user/index.xml. If you don't specify any parameters you'll get a listing of all users.
The base URL is /forum/index.xml. If you don't specify any parameters you'll get a list of all the parent topics.
The base URL is /pool/index.xml. If you don't specify any parameters you'll get a list of all pools.
The base URL is /pool/show.xml. If you don't specify any parameters you'll get a list of all pools.
The base URL is /pool/update.xml.
The base URL is /pool/create.xml.
The base URL is /pool/destroy.xml.
The base URL is /pool/add_post.xml. Potential error reasons: "Post already exists", "access denied"
The base URL is /pool/remove_post.xml. Potential error reasons: "access denied"