Skip to Content

Self-Hosted APIs

Rotate a service token

Get a new service token and keep the old one working while you switch over.

POST
/api/v2/service-token/rotate

You call it with the service token you want to replace. Works on cloud and self-hosted.

curl --request POST https://api.usedatabrain.com/api/v2/service-token/rotate \  --header "Authorization: Bearer $DATABRAIN_SERVICE_TOKEN" \  --header "Content-Type: application/json" \  --data '{ "expireAt": 86400 }'

Auth

The service token to rotate. A data app API token gets 400; use Rotate an API token for those. See Authentication.

If you lost the token, rotate it as a signed-in user: select Rotate token in Settings > Developers > Tokens, or call Rotate a token as a signed-in user.

Authorization

ApiToken
headerAuthorizationBearer <token>

A service token or a data app API token.

Body

expireAtnumberrequired

How many seconds the old token keeps working. 0 stops it at once. Not a date.

Response

{  "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a",  "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b",  "keyLast4": "4f5a"}

key is the new token. You see it only in this response. It has the old token's name and scopes, and no expiry. The old token is renamed <name> (replaced <date> UTC).

Errors

Statuserror.codeWhy
400INVALID_REQUEST_BODYexpireAt is missing
400AUTHENTICATION_ERRORInvalid Service Token: you used a data app API token
400EXPIRED_SERVICE_TOKENThis token is already being replaced, so it cannot rotate itself. Use the new token, or rotate in Settings > Developers > Tokens
400API_TOKEN_NAME_ALREADY_EXISTSAnother key already has the name the new token would get. Rename or delete it
400INVALID_SERVICE_TOKENThe token was not found
500INTERNAL_SERVER_ERRORThe rotation failed. The old token still works

For errors that every endpoint returns, see Authentication.

Example Request
curl -X POST 'https://api.usedatabrain.com/api/v2/service-token/rotate' \  -H 'Content-Type: application/json' \  -d '{  "expireAt": 86400}'
Example Response
{  "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a",  "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b",  "keyLast4": "4f5a"}