Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,910
Community Members
 
Community Events
165
Community Groups

How we can get a refresh token with rest api ?

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 Dec 04, 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}

Sorry if this sounds stupid but what is client_id?

Deleted user Feb 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.

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.

dblucas@charter.net

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

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

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
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,263 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you