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.
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.
DataAppApiTokenAuthorizationBearer <token>A data app API token. A service token is refused.
Body
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"}| Field | Description |
|---|---|
key | The new token. You see it only in this response |
keyId | The public id of the new token |
keyLast4 | The 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
| Status | error.code | Why |
|---|---|---|
| 400 | INVALID_REQUEST_BODY | expireAt is missing |
| 400 | INVALID_DATA_APP_API_KEY | You used a service token, or the token is already being replaced |
| 400 | API_TOKEN_NAME_ALREADY_EXISTS | Another token already has the name the new token would get. Rename or delete it, then rotate again |
| 500 | INTERNAL_SERVER_ERROR | The rotation failed. The old token still works |
For errors that every endpoint returns, see Authentication.
curl -X POST 'https://api.usedatabrain.com/api/v2/data-app/rotate-api' \ -H 'Content-Type: application/json' \ -d '{ "expireAt": 3600}'{ "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a", "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b", "keyLast4": "4f5a"}