Authentication error on pull requests/{id}/diffstat
Asked by Manatee:

Hello, Im trying to call this API using an APP password but Im getting rejected with this error.  
What can I do?  

{

"type": "error",

"error": {

"message": "The requested repository either does not exist or you do not have access. If you believe this repository exists and you have access, make sure you're authenticated."

}

}

I tried multiple app password with all permissions.  
Im using postman and passing my username and app password with Basic Auth as documentation suggested.  
I can't use OAuth 2.0, it is even possible?  
Because every other single call works.  
Thank you


Answers:
author: Mark C
body: Hi [@Manatee](/t5/user/viewprofilepage/user-id/1431537),

Thank you for reaching out to the community.

For us to test your app password and the API endpoint, would you be able to run the below CURL command on your local machine instead of Postman?

```
curl -I -u bb_username:app_password "https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/pullrequests/pr_id/diffstat"
```

Let's see if you're getting the 302 response according to the [API endpoint documentation](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-diffstat-get).

Let me know how it goes.

Regards,  
Mark C

comments: author: Manatee
body: Hi, it work and I get 302 but Im not understanding what I have to do.  
Because I tried using a Bearer and I get the info I was looking for, but I can't use it in my application


author: Manatee
body: Also I noticed that I was using as endpoint: bitbucket.org instead of api.bitbucket.org  
OMG, this was the error. So everything fixed now :D


author: Manatee
body: The API anyway worked using bitbucket.org/api/2.0/ but it wasn't the correct one


author: Manatee
body: I will explain which was my final goal, maybe you can help :)  
We open a pull request on Bitbucket with a merge conflict.

Now assuming that we don't know that there is a merge conflict, we want to know if there is one, using API, so we tried calling the API GET pull request/id but the answer doesnt say nothing about the merge conflict warning. Now we are looking for other API but there doesnt seem to be one


author: Mark C
body: Hi [@Manatee](/t5/user/viewprofilepage/user-id/1431537)  

You can actually extract the "location" value from the response header of the API result.  

Once extracted, you can use the URL to run another API command.

```
curl -u bb_username:app_password "<URL here>"
```

The result will be in JSON format and you can find the status with the "merge conflict" value. That means the file has a merge conflict.  
e.g.

```
"status" : "merge conflict",
```

<br />

Hope it helps.  

Regards,  
Mark C  

<br />


author: Manatee
body: Hi [@Mark C](/t5/user/viewprofilepage/user-id/1210823)

On which API are u referring?  
I tried on Postman:   
GET <https://api.bitbucket.org/2.0/repositories/chrmancini89/test/pullrequests/9/diffstat>  
GET <https://api.bitbucket.org/2.0/repositories/chrmancini89/test/pullrequests/9>  
But none of them have some field called "location", there is only one named: "X-Dc-Location" with a value of "Micros-3".  
Do you mind to be more precise about it?  
Thank you for your super help


author: Mark C
body: Hi [@Manatee](/t5/user/viewprofilepage/user-id/1431537)  

I'm not sure exactly how to do the same on Postman but I do see the "location" response header while using the CURL command below and run it on the terminal/command prompt:

```
curl -I -u bb_username:app_password "https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/pullrequests/pr_id/diffstat"
```

<br />

The URL is something like this:

```
location: https://api.bitbucket.org/2.0/repositories/workspace_id/repo_name/diffstat/workspace_id/repo_name:commit_hash?from_pullrequest_id=123
```

<br />

Regards,  
Mark C


Tags: bitbucket-cloud

cloud