Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How we can get a refresh token with rest api ?

Raza Rafaideen May 10, 2018

Bitbucket token is short living and expires soon. how can i get a refresh token with rest api ? 

2 answers

2 accepted

4 votes
Answer accepted
Deleted user December 4, 2018


In your browser go to 

https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code

Authorize under your bitbucket account.

After that, your browser will be redirected to 

{your_redirect_link}/?code={code}

Use the code to make another request in a terminal:

curl -X POST -u "{client_id:secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=authorization_code -d code={code}

The reponse will be look like that:
{
"access_token": "some_long_string",
"scopes": "team webhook account issue wiki pipeline pullrequest project snippet",
"expires_in": 7200,
"refresh_token": "the_string_you_need",
"token_type": "bearer"
}

Now you can refresh access_token with request

curl -X POST -u "{client_id}:{secret}" https://bitbucket.org/site/oauth2/access_token -d grant_type=refresh_token -d refresh_token={refresh_token}

svensyld February 18, 2019

Sorry if this sounds stupid but what is client_id?

Deleted user February 18, 2019

I order to use bitbucker api you need to generate a client_id (also known as a key) and a secret. You can do this in your settings page in OAuth section.

David Lucas October 29, 2021

How can we do this all in curl. I tied it and it fails. I do not want to use the browser. I need automation to refresh my token.

David Lucas October 29, 2021

dblucas@charter.net

David Lucas October 31, 2021

I have had 5 people try this and there is no output at all.

curl -o C:/tmp/refreshTokenCode.txt -X GET https://bitbucket.org/site/oauth2/authorize?client_id={MY CLIENT ID}&response_type=code

No output from curl

1 vote
Answer accepted
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2018

Hi! 

 

 curl -X POST -u "client_id:secret" \
  https://bitbucket.org/site/oauth2/access_token \
  -d grant_type=refresh_token -d refresh_token={refresh_token}

https://developer.atlassian.com/bitbucket/api/2/reference/meta/authentication#refresh-tokens

 

Also, it will be nice if you provide pull request regarding that in this small routine reducer project. (https://github.com/AstroMatt/atlassian-python-api)

 

Cheers,

Gonchik Tsymzhitov

hud_sync October 18, 2018

I don't think the answer explained how to get the {refresh_token} itself

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events