Getting 401 error for a valid Bitbucket user account, when trying to access API from Jira cloud
Asked by ppushpam:

Hi,

I am trying to invoke Bitbucket API from Jira using automation rule. I used a service account created in Bitbucket for authorization, it was working fine but recently we had an Atlassian outage which was there for 7 days. After that, our old app pwds were invalid so created a new app pwd, and converted it to base64 "username:apppwd" and using this string to invoke the API, but I am getting 401 error.

When I tried my personal username, its working fine and not working with service account, the service account status is enabled in Bitbucket. Could you please help.

Thanks


Answers:
author: Theodora Boudale
body: Hi [@ppushpam](/t5/user/viewprofilepage/user-id/4607883),

I would suggest checking the following:

**1)** Have you generated the app password for the service account or for your personal account?

If you are using the username of the service account, the app password should be generated for the service account.

Please make sure that the app password has enough permissions for the operation you want to perform.

<br />

**2)** After you generate the app password for the service account, can you try running the API call with **curl** from your terminal, for testing purposes?

An example would be the following:

```
curl -u username:app-password https://api.bitbucket.org/2.0/repositories/workspace-id
```

replace **username** and **app-password** with the values for username and app password of the service account, and also the API URL with the one you are using.

What is the output of this call in your terminal?

Kind regards,  
Theodora

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

Thankyou for your response!

1. I created the app pwd for the service account, providing it full access and admin access.

2. I used the curl command and output is authorized, I got "200" response.

![Creds issue.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/194492i3DD41F1FC3F296D1/image-size/large?v=v2&px=999 "Creds issue.PNG")

But when I am using it in the Jira automation rule, it says unauthorized. I converted "username:app-password" to Base64 string and using it in the header as :

Authorization: Basic "Converted string"


author: Theodora Boudale
body: Hi [@ppushpam](/t5/user/viewprofilepage/user-id/4607883),

Thank you for the info. Could you please try one more thing:

Run from terminal

```
curl -v https://api.bitbucket.org/2.0/repositories/workspace-id/ -H "Authorization: Basic converted_string"
```

where

**<https://api.bitbucket.org/2.0/repositories/workspace-id/>** Replace with the API URL you use in your Jira Automation rule

**converted_string** replace with your Base64 string without any extra quotes

and let me know the output you get (200 or 401). This is to double-check whether the issue may be with the converted string.

Kind regards,  
Theodora


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

Please find the output of curl command in the attached image, it doesn't contain whole output, Let me know if you want the full output content.

![Bitbucket_output.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/194703iADE81443A00A1854/image-size/large?v=v2&px=999 "Bitbucket_output.PNG")


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

Following up on the issue, was this output helpful to interpret the cause?


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

The issue is fixed now, Thanks a lot for your help.


author: Theodora Boudale
body: Hi [@ppushpam](/t5/user/viewprofilepage/user-id/4607883),

It's good to hear that the issue has been fixed. Was there a problem with the converted string? The output you posted in the attached image shows a 401 response as well, so I would assume that the culprit is with this string.

Kind regards,  
Theodora


author: ppushpam
body: Hey [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ,

Looks like there was some confusion with the service account username I was considering, later i used the correct username and it worked ass expected.

Thanks


author: Theodora Boudale
body: Thank you for the update on this, I'm glad you figured this out.

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

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud

jira