Skip to Content

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.

POST
/api/v2/service-token/rotate-from-app

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.

Authorization

AdminJwt
headerAuthorizationBearer <JWT>

Self-hosted only: the admin JWT from Create admin JWT.

Body

tokenIdstringrequired

The keyId of the service token or data app API token, from the create response or List API tokens

expireAtnumberrequired

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

Statuserror.codeWhy
400INVALID_REQUEST_BODYA field is missing, or tokenId is not a UUID. The message calls it "token"
401UNAUTHORIZEDNo access token was sent
403FORBIDDENYou do not have permission to rotate tokens.
404TOKEN_NOT_FOUNDNo token of your organization has this keyId
500INTERNAL_SERVER_ERRORThe rotation failed
Example Request
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}'
Example Response
{  "key": "7d2e4f6a-1b3c-4d5e-8f9a-0b1c2d3e4f5a",  "keyId": "e5f6a7b8-c9d0-4e1f-8a2b-3c4d5e6f7a8b",  "keyLast4": "4f5a"}