How to renew personal access tokens via REST API's in Bitbucket Server

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform Notice: Server and Data Center Only - This article only applies to Atlassian products on the server and data center platforms.

Summary

How to renew Tokens in Bitbucket incase if one gets expired.

Environment

7.3.0

Workaround

At the moment, We don't have any API that can directly renew/refresh the token. However, we can use the following API's as a workaround. This works as follows:

  • 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.

Fetch the list of all tokens associated with a user( john_doe is the user I'll be refreshing the tokens for )

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":"manan.baba","emailAddress":"test@email.com","id":52,"displayName":"Manan","active":true,"slug":"manan.baba","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/manan.baba"}]}}},{"id":"343808353895","createdDate":1610521501107,"name":"token","permissions":["REPO_READ","PROJECT_READ"],"user":{"name":"manan.baba","emailAddress":"test@email.com","id":52,"displayName":"Manan","active":true,"slug":"manan.baba","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/manan.baba"}]}}}],"start":0}%   

Delete the token

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

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":"manan.baba","emailAddress":"test@email.com","id":52,"displayName":"Manan","active":true,"slug":"manan.baba","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/manan.baba"}]}}},{"id":"343808353895","createdDate":1610521501107,"name":"token","permissions":["REPO_READ","PROJECT_READ"],"user":{"name":"manan.baba","emailAddress":"test@email.com","id":52,"displayName":"Manan","active":true,"slug":"manan.baba","type":"NORMAL","links":{"self":[{"href":"http://localhost:7994/users/manan.baba"}]}}}],"start":0}%       

Last modified on Apr 20, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.