Discourse API Documentation (latest)

This page contains the documentation on how to use Discourse through API calls.

Note: This documentation is not complete, so for missing parts you may have to reverse engineer the Discourse API to figure out how to use an API endpoint.

Request Content-Type

The Content-Type for POST and PUT requests can be set to application/x-www-form-urlencoded , multipart/form-data , or application\json .

Endpoint Names and Response Content-Type

Most API endpoints provide the same content as their HTML counterparts. For example the URL /categories serves a list of categories, the /categories.json API provides the same information in JSON format.

Instead of sending API requests to /categories.json you may also send them to /categories and add an Accept: application/json header to the request to get the JSON response. Sending requests with the Accept header is necessary if you want to use URLs for related endpoints returned by the API, such as pagination URLs. These URLs are returned without the .json prefix so you need to add the header in order to get the correct response format.

Authentication

Some endpoints do not require any authentication, pretty much anything else will require you to be authenticated.

To become authenticated you will need to create an API Key from the admin panel.

Once you have your API Key you can pass it in along with your API Username as an HTTP header like this:

curl -X GET "http://127.0.0.1:3000/admin/users/list/active.json" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: discourse1"

and this is how POST requests will look:

curl -X POST "http://127.0.0.1:3000/categories" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: 714552c6148e1617aeab526d0606184b94a80ec048fc09894ff1a72b740c5f19" \
-H "Api-Username: discourse1" \
-F "name=89853c20-4409-e91a-a8ea-f6cdff96aaaa" \
-F "color=49d9e9" \
-F "text_color=f0fcfd"

Categories

Get a list of categories

The Categories endpoint returns a list of all the categories for your discourse site that you have access to.

Responses

200 A category_list object that contains an array of categories

GET
 /categories.json

Server URL

https://discourse.example.com/categories.json

RESPONSE SAMPLES

  • 200 A category_list object that contains an array of categories
{
  "category_list": {
    "can_create_category": true,
    "can_create_topic": true,
    "draft": true,
    "draft_key": "string",
    "draft_sequence": 0,
    "categories": [
      {
        "id": 0,
        "name": "string",
        "color": "string",
        "text_color": "string",
        "slug": "string",
        "topic_count": 0,
        "post_count": 0,
        "position": 0,
        "description": "string",
        "description_text": "string",
        "topic_url": "string",
        "logo_url": "string",
        "background_url": "string",
        "read_restricted": true,
        "permission": 0,
        "notification_level": "string",
        "can_edit": true,
        "topic_template": "string",
        "has_children": true,
        "topics_day": 0,
        "topics_week": 0,
        "topics_month": 0,
        "topics_year": 0,
        "topics_all_time": 0,
        "description_excerpt": "string"
      }
    ]
  }
}

Refer: https://docs.discourse.org/#tag/Categories