Self-Hosted APIs
Rotate a token as a signed-in user
Replace a service token or data app API token by its keyId, also when you lost the token.
This is the API behind Rotate token in the app. You need a user's access token and the token's keyId, not the token itself.
curl --request POST https://databrain-api.example.com/api/v2/service-token/rotate-from-app \ --header "Authorization: Bearer $ADMIN_ACCESS_TOKEN" \ --header "Content-Type: application/json" \ --data '{ "tokenId": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f", "expireAt": 3600 }'Auth
Authorization: Bearer <accessToken>, a user's access token, for example from Create an admin JWT on self-hosted. The user needs permission to create API tokens. To rotate the company service token (a token with no data app), the user must be an Admin. To rotate a data app key, the permission is enough.
AdminJwtAuthorizationBearer <JWT>Self-hosted only: the admin JWT from Create admin JWT.
Body
The keyId of the service token or data app API token, from the create response or List API tokens
How many seconds the old token keeps working. 0 stops it at once.
A token that is already being replaced can be rotated again. Its end time never moves later.
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.
Errors
| Status | error.code | Why |
|---|---|---|
| 400 | INVALID_REQUEST_BODY | A field is missing, or tokenId is not a UUID. The message calls it "token" |
| 400 | API_TOKEN_NAME_ALREADY_EXISTS | Another key already has the name the new token would get. Rename or delete it |
| 400 | INVALID_SERVICE_TOKEN or INVALID_DATA_APP_API_KEY | The token could not be rotated. Try again |
| 401 | UNAUTHORIZED | No access token was sent |
| 403 | FORBIDDEN | You do not have permission to rotate tokens. |
| 403 | SERVICE_TOKEN_ADMIN_ONLY | Only an admin can rotate a service token. The token has no data app and the user is not an Admin |
| 404 | TOKEN_NOT_FOUND | No token of your organization has this keyId |
| 400 or 500 | INTERNAL_SERVER_ERROR | The rotation failed. You also get 500 when expireAt is not a number of seconds, for example a date |
curl -X POST 'https://api.usedatabrain.com/api/v2/service-token/rotate-from-app' \ -H 'Content-Type: application/json' \ -d '{ "tokenId": "c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f", "expireAt": 3600}'{ "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a", "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b", "keyLast4": "4f5a"}