Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Getting all repositories under the workspace

Hi Guys

im having troubles to generate access token with simple curl ... I need this access token in order to execute 

curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'

 

in the documentation :

https://developer.atlassian.com/cloud/bitbucket/rest/intro/#authentication

i can't find the the curl command for authenticate...

tried to :

 curl --request GET https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=token

 

and got : no matches found....

 

I appreciate any help here

Thanks

Eyal

 

1 answer

0 votes

Hi @Eyal David and welcome to the community!

Please see below the steps to obtain the access token:

1. After you create the OAuth consumer in the Bitbucket workspace, open a tab in your browser and enter the following URL:

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

Replace {consumer_key} with the key of the OAuth consumer, no brackets in the URL, and then hit Enter.

If the callback URL you set for the OAuth consumer was e.g. http://localhost, you will get redirected to something like

http://localhost/?code=fpYPDYsryEpsRawrj4

Copy the code from that URL: fpYPDYsryEpsRawrj4

Please note this step needs to be executed on your browser, it is not possible to obtain the code with curl.

2. You can then obtain an access token by executing the following command

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

Replace key with the consumer's key
Replace secret with the consumer's secret
Replace the code value in there (fpYPDYsryEpsRawrj4) with your code from the previous step

3. The output will include an access_token field and a refresh_token field.

You can use the value of the access token for 2 hours in your API calls before it expires.

You will then have to use the refresh token from the output in step 2 to get a new access token and a new refresh token.

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

Replace key with the consumer's key
Replace secret with the consumer's secret
Replace the value of the refresh_token in there (2Eoiw6UJ707AD9aIyUR) with the one from your output in step 3.

This command will give you a new access token and a new refresh token and you can use this command from now on to generate new access and refresh tokens when each access token expires.

If you have any questions, please feel free to let me know.

Kind regards,
Theodora

@Theodora Boudale Thank you very much for your fast response.

is there a way to get all repositories names under the workspace ?

i'm using :

"curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/${workspace}' \
--header 'Authorization: Bearer ${token}' \
--header 'Accept: application/json'"

the json doesn't include the list of repositories under the account .... i used the company name as workspace

any suggestion ?

Thanks

Eyal

Hi Eyal,

I would suggest checking first if the OAuth consumer has Read permissions for Repositories (from the workspace's Settings > OAuth consumers > Edit the consumer).

If the permissions look ok, could you please let me know:
1. Did you generate the OAuth consumer for the company workspace? Or for your personal workspace?
2. Do you get no output at all when you run this call?
3. Could you run the curl call with the flag -vv as well and copy-paste the output here?
(Please make sure to remove any sensitive info from the output prior to sharing it, like the access token, x-consumer-client-id, any workspace/repo urls etc)
4. Can you confirm if you are using in the url the workspace ID that can be found here https://bitbucket.org/company-workspace/workspace/settings where company-workspace replace with the one of your company's workspace?

I see that you have created a support ticket for this issue as well, so if you don't feel comfortable sharing any of this info here, you can also share it in the support ticket, which is visible only to you and Atlassian staff.

Kind regards,
Theodora

@Theodora Boudale 

it worked out that i didn't do the pagination ... once did it got all the repositories 

Thanks 

Eyal 

Hi Eyal,

Thank you for the update, I'm glad that you figured this out.

Please feel free to reach out if you ever need anything else!

Kind regards,
Theodora

@Theodora Boudale 

Thank you very much ! appreciated !

Like Theodora Boudale likes this

Suggest an answer

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

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,491 views 4 8
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