Getting 404 error when fetching commit data, despite successfully fetching repositories and PRs?
Asked by Amin Lajmi:

I'm facing an issue with our custom integration that is designed to fetch the list of repositories, pull requests, and commits. The calls are made with a token generated using OAuth consumer authorised by an admin user.  
I am able to retrieve the list of repositories and pull requests successfully, but when attempting to fetch the commit data, in some cases I receive a 404 error with the message "The source or destination could not be found."

Here's a description of the issue I'm encountering, highlighting the steps and relevant details:

1. The custom integration uses OAuth consumers to authorize access for admin users.
2. The purpose of the custom integration is to gather the repositories, pull requests, and commits data of third party workspaces (so the specific setup of those workspaces are unknown).
3. The admin token generated from OAuth has the following scopes: `account`, `pullrequest`, `issue`, `webhook`, and `team`.
4. The first two API calls to fetch repositories and pull requests data work as expected, returning the desired data.
5. When attempting to fetch the commit data (third call), a 404 error is encountered, with the message "The source or destination could not be found."

### Steps Taken to Solve the Problem: {#toc-hId-2063314942}

I have attempted the following steps to resolve the issue:

1. Double-checked the API call URLs to ensure they are valid and correspond to the proper endpoints.
2. Verified the admin token permissions to make sure it has the required access rights to fetch commit data.
3. Looked through Bitbucket's API documentation for any necessary changes in query parameters or requirements for fetching commit data.
4. Ensured that the OAuth consumer is properly configured for admin users.

Unfortunately, after trying the above troubleshooting steps, the problem persists.

The API call URL format is: **<https://api.bitbucket.org/2.0/repositories/>\<workspace-name\>/\<repository-name\>/pullrequests/\<pullrequet-id\>/commits?pagelen=10**

### Screenshots: {#toc-hId-255860479}

To provide more context, I've included the following screenshot for OAuth consumer permissions:

![Screenshot 2023-09-29 at 15.58.13.png](/t5/image/serverpage/image-id/283690i93EC5A87F62B0E54/image-size/large?v=v2&px=999 "Screenshot 2023-09-29 at 15.58.13.png")

I would appreciate any guidance or suggestions from the community regarding the possible causes of this issue and how it might be resolved. Are there any additional steps I should take to further troubleshoot the problem, or any known issues that could be causing such an error when using OAuth consumers for admin users?

Thank you in advance for your help!


Answers:
author: Theodora Boudale
body: Hi Amin and welcome to the community!

This error doesn't have anything to do with the OAuth consumer, it occurs when the list of commits involved in the PR doesn't exist. This can happen if someone rewrites history or rebases and with a force push removes commits associated with a pull request. The API then returns a 404 error with this message since the list of commits doesn't exist.

Kind regards,  
Theodora

comments: author: Amin Lajmi
body: [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) Thank you for your response.


Tags: bitbucket-cloud

cloud