Issue with 401 Error for api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits
Asked by ???SA:

Hi,

When configuring a Bamboo plan environment, the repository to be used was added under the Default plan configuration \> Repositories menu.  
Currently, the method to connect Bamboo to Bitbucket Cloud involves adding an app password from the Bitbucket Cloud account, and then adding this key under the Bamboo Shared Credentials menu, which allowed successful registration.  
However, as of September 6th, repository registration is failing for all IDs except for a specific ID's Shared Credentials. My account has admin privileges on both Bitbucket and Bamboo, but I am still unable to register repositories (this was previously working without any issues).  
The currently applied plans are still functional, but there is a problem when trying to register additional repositories.

Upon checking, the account that works can query the URL without any issues, but the app password of the problematic account returns a 401 error with the following request: <https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits>

I would like to know the reason for the 401 error and the solution, even though both accounts have the same permissions.


Answers:
author: Theodora Boudale
body: Hi [@???SA](/t5/user/viewprofilepage/user-id/5152256),

A 401 error means that the credentials provided are not valid.

Are you also using a username along with the app password? An app password cannot be used by itself for authentication. You need to provide the Bitbucket username of the account that you generated the app password for. The username can be found on the following page, after you log in to the account:

* <https://bitbucket.org/account/settings/>

I suggest the following steps to confirm if the credentials are correct and work:

**1.** Log in to <https://bitbucket.org> with the account you generated the app password for

**2.** Double check the username listed here: <https://bitbucket.org/account/settings/>

**3.** Then, run the following curl command from a terminal application on your computer:

```
curl -u username:app_password --request GET \
--url https://api.bitbucket.org/2.0/repositories/workspace-id/repo-slug/commits \
--header 'Accept: application/json'
```

where

**username** replace with the Bitbucket username from step 2  
**app_password** replace with the app password you generated for this account  
**workspace-id** replace with the id of the workspace where this repo belongs  
**repo-slug** replace with the slug for the repo

Do you get the repo's commits when you execute this curl call?

Kind regards,  
Theodora

comments: author: ???SA
body: Hi, [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086)

I try to curl, but it occur 401 error


author: Theodora Boudale
body: Hi [@???SA](/t5/user/viewprofilepage/user-id/5152256),

Thank you for your reply.

Since the curl command also fails, then the credentials are not correct.

If you have ensured that the username is correct, please generate a new app password from

* <https://bitbucket.org/account/settings/app-passwords/>

and then try the **curl** command with the new app password. Does it succeed then?

If you only need to perform a GET to the commits endpoint, then **Repositories - Read** permissions for the app password are enough. For Bamboo, if Bamboo makes additional operations other than cloning or getting commits, then additional permissions may be needed for the app password.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud