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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I refresh a token

- My first access token get expired, now I want a new token without any User interface.

- I tried below in terminal,  

curl -X POST -u "{key}:{secret}" -d 
grant_type=refresh_token -d refresh_token={refresh_token}

but getting, below error

{"error_description": "Invalid refresh_token", "error": "invalid_request"}


Questions :

 1. What parameter should we pass to refresh_token? we need a new access token then why need this field?


I tried, expired token and new  access token(created using UI) as well but it not worked


Please help me to understand what parameter should we pass to the refresh_token

And how can I generate new token using terminal/curl





1 answer

0 votes

Hi Arun,

When you generated your very first access token with a command like

curl -X POST -u "{key}:{secret}" -d grant_type=authorization_code -d code={code}

the output should have been like this:

"access_token" : 5cEig-w1wXrlbM876XY1Nu-w5WfObqP0EOYo2JOPzs615QxZTqI9z8Gsy_21yX23Uspwblt8eKeBAcwpCrHY=,
"scopes": "repository",
"expires_in" : 7200,
"refresh_token" : 4Etiw6UP808AU3rIoUW,
"token_type" : bearer

You need to use the value of the field 'refresh_token' above in your call.

Afterwards, when you execute the following command with this value for the refresh token

curl -X POST -u "{key}:{secret}" -d grant_type=refresh_token -d refresh_token={refresh_token}

you will get in the output a new authorization code, and a new refresh token which you can use after the 2 hours expiry, and so on.

Please feel free to let me know if you have any questions.

Kind regards,

Hi Theodora

Thanks for quick response.

curl -X POST -u "{key}:{secret}" -d grant_type=authorization_code -d code={code}

 When we are using the {code}, parameter do we have any expiry for it? Because it seems get invalid once get used.

{"error_description": "The specified code is not valid.", "error": "invalid_grant"}

Hi Arun,

The following command

curl -X POST -u "{key}:{secret}" -d grant_type=authorization_code -d code={code}

you only use it once, in the beginning.

After the first time you use it, you execute the other command:

curl -X POST -u "{key}:{secret}" -d grant_type=refresh_token -d refresh_token={refresh_token}

After the 2 hours expiry, you also use

curl -X POST -u "{key}:{secret}" -d grant_type=refresh_token -d refresh_token={refresh_token}

This will give you both an authorization code and a refresh token to use the next time you execute it.

Does this help?

Kind regards,

It Help me lot.

Thanks Theodora

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,573 views 1 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