Skip to Content

API Tokens

Rotate an API token

Replace a data app API token with a new one, and keep the old one working for a while.

POST
/api/v2/data-app/rotate-api

You call it with the token you want to replace. You get a new token, and the old one keeps working for expireAt seconds. POST /api/v2/data-app/api-tokens/rotate does the same.

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

Auth

The data app API token to rotate. A service token gets 400 INVALID_DATA_APP_API_KEY. See Authentication.

You need the current token. If you lost it, select Rotate token in Data Apps > API tokens, or create a new token.

Authorization

DataAppApiToken
headerAuthorizationBearer <token>

A data app API token. A service token is refused.

Body

expireAtnumber | stringrequired

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"}
FieldDescription
keyThe new token. You see it only in this response
keyIdThe public id of the new token
keyLast4The last 4 characters of the new token

The new token gets the old token's name. The old token is renamed <name> (replaced <date> UTC) and expires after expireAt seconds. A token that is already being replaced cannot be rotated again.

Errors

Statuserror.codeWhy
400INVALID_REQUEST_BODYexpireAt is missing
400INVALID_DATA_APP_API_KEYYou used a service token, or the token is already being replaced
400API_TOKEN_NAME_ALREADY_EXISTSAnother token already has the name the new token would get. Rename or delete it, then rotate again
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/data-app/rotate-api' \  -H 'Content-Type: application/json' \  -d '{  "expireAt": 3600}'
Example Response
{  "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a",  "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b",  "keyLast4": "4f5a"}