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

Getting all repositories under the workspace

Eyal David December 16, 2021

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

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 17, 2021

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

Eyal David December 19, 2021

@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

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2021

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

Eyal David December 20, 2021

@Theodora Boudale 

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

Thanks 

Eyal 

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 20, 2021

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

Eyal David December 20, 2021

@Theodora Boudale 

Thank you very much ! appreciated !

Like Theodora Boudale likes this
Kumaran Ramalingam
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 5, 2024

@Eyal David 

Could you please let me know how did you used pagination concept here to get the list of all repositories.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 5, 2024

Hi @Kumaran Ramalingam and welcome to the community!

If the API returns more than one page, there will be a field called next in the output. The value of this field is the link to the next page of the results, so you can use it to run another API call to get the second page. If there is a third page, you will again see a next field with the link to the third page. The lack of a next link in the response indicates the end of the collection.

You can read more about pagination here:

Kind regards,
Theodora

Kumaran Ramalingam
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 8, 2024

Hi @Theodora Boudale

Thank you Sir That really helped me a lot actually the real issue was the request python module when I am using it I didnt pass the Basic HTTP authentication properly but still I was getting the paginated results that coz its the public repository I was getting (without authentication). After using HTTPrequest Basic Authentication Method parsed Username and app password made my day.

Ur insight on this helped me a lot to use python to loop over the page number to achieve the same. Thanks you a lot. Have a great day.

Like Theodora Boudale likes this
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 8, 2024

Thank you for the update and you are very welcome, I'm glad I could help!

Have a nice day too!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events