How to renew personal access tokens via REST API's in Bitbucket Server
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
How to renew Tokens in Bitbucket incase if one has expired.
Solution
Environment
7.3.0
Workaround
Bitbucket Server does not provide a way to renew or refresh a token via the REST API. However you can use the following approach as a workaround:
Fetch the list of all tokens associated with a user.
Delete the token which has expired or isn't required further.
Re-create the token.
You can use the REST API methods described below for this. In all examples replace <username>
with the Bitbucket Server username of the user whose token you want to delete and re-create, and <base_URL>
with the base URL of your Bitbucket Server instance.
Fetch the list of all tokens associated with a user
1
2
3
curl -k -u <username> -H 'Content-Type: application/json' -H 'Accept: application/json' <base_URL>/rest/access-tokens/1.0/users/<username>
{"size":2,"limit":25,"isLastPage":true,"values":[{"id":"075905477751","createdDate":1610525968583,"name":"access token name","permissions":["REPO_ADMIN","PROJECT_READ"],"user":{"name":"john.doe","emailAddress":"test@email.com","id":52,"displayName":"John Doe","active":true,"slug":"john.doe","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/john.doe"}]}}},{"id":"343808353895","createdDate":1610521501107,"name":"token","permissions":["REPO_READ","PROJECT_READ"],"user":{"name":"john.doe","emailAddress":"test@email.com","id":52,"displayName":"John Doe","active":true,"slug":"john.doe","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/john.doe"}]}}}],"start":0}%
Delete the token
1
curl -k -u <username> -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' <base_URL>/rest/access-tokens/1.0/users/<username>/<tokenID>
Re-create the token
1
curl -k -u <username> -X PUT -d '{"name": "access token name","permissions": [ "REPO_ADMIN","PROJECT_READ"]}' -H 'Content-Type: application/json' -H 'Accept: application/json' <base_URL>/rest/access-tokens/1.0/users/<username>
Was this helpful?