Skip to main content

Access Tokens and API

Create a personal access token for each script or app, then call the control panel's API with it to read settings and logs, change features, or start and stop the bot.

Why Use Access Tokens?

  1. Lets scripts, dashboards, and shortcuts use the API without your password or a browser sign-in.
  2. Gives each client only the scopes it needs, so a leaked token can't do everything you can.
  3. Lets you revoke one client without affecting the others.
  4. Ends temporary access on its own when you set an expiry.

How Tokens Work

Scopes

ScopeWhat it allows
features:readSee your servers with their channels and roles, feature settings, and the invite page
features:writeChange feature settings, turn features on or off, and edit the invite page
bot:controlSee the bot's status, and start, stop, or restart it
logs:readRead the bot, web, and worker logs

Create a Token

  1. Open Access tokens and select Create token.
  2. Enter a Name you'll recognize, like the app that uses it, up to 80 characters. Each of your tokens needs its own name, and names that differ only in letter case count as the same.
  3. Under Scopes, tick what the client can do.
  4. Under Expires, choose Never, In 30 days, In 90 days, or In 1 year.
  5. Select Create token.
Create token dialog with the name Uptime monitor, only the bot:control scope ticked, and Expires set to In 90 days
Creating a token

Copy the Token Once

The dialog then shows the new token once, under Token for and its name, with "Copy it now. It won't be shown again." and a copy button. Copy it before you select Done.

  1. Select the copy button next to the token, and save the token in the client's secret store.
  2. Select Done.
Token for Uptime monitor dialog, which asks you to copy the token now, the token with a copy button, and Done
A new token, shown once

A lost token can't be shown again, so create a new one and revoke the old one.

Edit or Revoke a Token

Each row on Access tokens shows the token's name and scopes, when it was created and last used, and when it expires.

  • Edit — Changes the name, the scopes, and the expiry, while the token's value stays the same. When an expiry is set, Keep and its date stay selected, and Never removes it.
  • Revoke — Select Revoke, then Revoke again to confirm. Apps using the token stop working right away, and the row disappears.
  • Expired — An expired token stays in the list and is rejected, so edit it to set a new expiry, or revoke it.

To rotate a token, create a replacement with the same scopes, update the client and check that one request works, then revoke the old token.

Call the API

The Calling the API section of the page shows the Base URL, the header, and the main paths with the scope each one needs.

  • Base URL — The address your browser has the control panel open at, such as https://bot.example.com. Every path starts with /api/v1.
  • Header — Send Authorization: Bearer dsb_… with every request, and a token request never needs the browser's CSRF header.
  • JSON — Send bodies as JSON with Content-Type: application/json, and answers are JSON. An image upload sends the raw PNG, JPEG, WebP, or GIF file with its own Content-Type instead, and /logs/stream answers with server-sent events.

Passing the token with curl's -H option puts it in the process list, where other users on the machine can see it. Piping the header to curl's --config - keeps it out, as long as printf is the shell's builtin:

bash
read -r -s STONKER_TOKEN

printf 'header = "Authorization: Bearer %s"\n' "$STONKER_TOKEN" \
  | curl --config - --silent --show-error --fail-with-body \
      https://bot.example.com/api/v1/bot

unset STONKER_TOKEN

read -r -s reads the token without showing it or saving it to the shell history, and the examples below use the same pattern.

Endpoints

Method and pathScopeWhat it does
GET /api/v1/auth/meAnyShows the token's ID, name, scopes, and username
GET /api/v1/serversfeatures:readLists the servers you can open, with how many features each has on
GET /api/v1/servers/{serverId}/resourcesfeatures:readLists a server's channels and roles
GET /api/v1/servers/{serverId}/featuresfeatures:readLists all 19 features with their state
GET /api/v1/servers/{serverId}/features/{featureKey}features:readShows one feature's settings, form, and example
PUT /api/v1/servers/{serverId}/features/{featureKey}features:writeSaves one feature's settings
PUT /api/v1/servers/{serverId}/features/{featureKey}/enabledfeatures:writeTurns one feature on or off
GET /api/v1/servers/{serverId}/invite-pagefeatures:readShows the invite page design and its public link
PUT /api/v1/servers/{serverId}/invite-pagefeatures:writeSaves the invite page design
POST /api/v1/servers/{serverId}/invite-page/imagesfeatures:writeUploads a logo or banner image
GET /api/v1/botbot:controlShows the bot's status
POST /api/v1/bot/actionsbot:controlStarts, stops, or restarts the bot
GET /api/v1/logslogs:readLists log entries
GET /api/v1/logs/streamlogs:readSends new log entries as they arrive, as server-sent events
  • serverId — A Server ID from GET /api/v1/servers. A server your account can't open answers like an unknown one, with "That Discord server isn't available."
  • featureKey — The feature's settings key, which is its config.json section name, such as auto-replies, message-proxies, or web-applications.

Restart the Bot

bash
printf 'header = "Authorization: Bearer %s"\n' "$STONKER_TOKEN" \
  | curl --config - --silent --show-error --fail-with-body \
      --header 'Content-Type: application/json' \
      --request POST \
      --data '{"action":"restart"}' \
      https://bot.example.com/api/v1/bot/actions

The answer is HTTP 202 with {"desiredState":"running"}, and the bot picks the request up within a second or so. action is start, stop, or restart, and GET /api/v1/bot then reports the status: ready, starting, stopped, failed, configuration_required, or unresponsive.

Turn a Feature On

bash
printf 'header = "Authorization: Bearer %s"\n' "$STONKER_TOKEN" \
  | curl --config - --silent --show-error --fail-with-body \
      --header 'Content-Type: application/json' \
      --request PUT \
      --data '{"enabled":true}' \
      https://bot.example.com/api/v1/servers/123456789012345678/features/auto-replies/enabled

Turning a feature on checks its saved settings first. A feature that isn't set up answers HTTP 409 with "Set up this feature before turning it on."

Read New Log Entries

bash
printf 'header = "Authorization: Bearer %s"\n' "$STONKER_TOKEN" \
  | curl --config - --silent --show-error --fail-with-body \
      'https://bot.example.com/api/v1/logs?component=bot&level=warn&limit=50'
  • Filters — component is bot, web, or worker, level is the lowest level to include, q searches event names and details, and limit takes 1 to 500, 200 by default.
  • Only newer entries — The answer has items and a cursor, and sending after=<cursor> next time returns only the entries written since.

Save a Feature's Settings

Read the feature first, then send the whole configuration back with the expectedRevision you read and any new secret values in secrets.

PUT /api/v1/servers/123456789012345678/features/message-proxies
json
{
  "configuration": [
    {
      "name": "Relay news bot",
      "channel": { "channel-id": "123456789012345678" },
      "webhook": { "webhook-url": { "$secret": "" } }
    }
  ],
  "expectedRevision": 3,
  "secrets": {
    "/0/webhook/webhook-url": "https://discord.com/api/webhooks/123456789012345678/your-webhook-token"
  }
}
  • New secrets — Put { "$secret": "" } where the secret goes, and send its value in secrets, keyed by the JSON pointer to that spot.
  • Saved secrets — Keep the { "$secret": "<key>" } you read, and leave it out of secrets.
  • Conflicts — If someone saved the feature since you read it, the answer is HTTP 409 with "This feature changed since you opened it. Reload to see the latest version."

Responses and Errors

A failed request answers with an error object that has a stable code for scripts and a message for people.

A token without the scope
json
{
  "error": {
    "code": "scope_required",
    "message": "This token doesn't have the bot:control scope."
  }
}

A body that fails its checks also lists each problem in issues, with the field, the message, and the path as a list. The top-level message repeats the first one, except when turning on a feature whose saved settings fail, which answers "Fix this feature's settings before turning it on."

A body that failed its checks
json
{
  "error": {
    "code": "invalid_request",
    "message": "Choose start, stop, or restart.",
    "issues": [
      {
        "field": "action",
        "message": "Choose start, stop, or restart.",
        "path": ["action"]
      }
    ]
  }
}

Status Codes

StatusError codeMeaning
200—The request worked
201—An image upload worked, and the answer has the image's id and url
202—The bot accepted a start, stop, or restart
400invalid_jsonThe body isn't valid JSON
401authentication_requiredThe token is missing, malformed, unknown, expired, or revoked, or its owner is suspended
403scope_requiredThe token lacks the route's scope
403permission_requiredYour role can't make this change, such as "Your role can't change settings."
403session_requiredThe route needs a signed-in browser session
404server_not_foundThe server doesn't exist, or your account can't open it
404feature_not_foundThe feature key doesn't exist
404not_foundNo route matches the method and path
409revision_conflictSomeone saved the feature or the invite page after you read it
409feature_not_configuredThe feature isn't set up yet
409bot_token_requiredNo Bot Token is saved, so the bot can't start
413payload_too_largeThe body is over 64 KB, or over 2 MB for a feature save or an image upload
415unsupported_encodingThe body isn't UTF-8 JSON
415unsupported_imageAn upload isn't a PNG, JPEG, WebP, or GIF image
422invalid_requestA field failed its check, and issues lists each problem
429rate_limitedThe address sent more than 300 requests in a minute
500internal_errorSomething unexpected went wrong, and the Web log has the detail

The checks run in order: the JSON body, the rate limit, the token, its scope, your role, the server, and then the body's fields.

Rate Limits

  • Limit — Every path under /api/v1, including the control panel's own requests, allows 300 requests per minute from one address, or one /56 network for IPv6.
  • Headers — Answers carry RateLimit-Policy, RateLimit-Limit, RateLimit-Remaining, and RateLimit-Reset, and a 429 also carries Retry-After in seconds.
  • Behind a proxy — The address comes from X-Forwarded-For when a trusted proxy sends it, as described in Remote Access.

Routes Tokens Can't Use

Some routes need a signed-in browser session, so a token gets 403 with "A signed-in browser session is required."

A request with an Authorization header is always handled as a token request, even when the browser also sends a session cookie.