I am trying to access the commits of a PR using the following, but I keep getting a 403 error, forbidden url.
Hi David,
What form of authentication are you using to make the API call? Is it username+password? Or username+app-password? Or OAuth?
In case you're using an app password or OAuth, it is possible that the app password or OAuth consumer doesn't have permissions for pull requests. There are separate permissions for pull requests when creating either an app password or an OAuth consumer.
You can check and change permissions for an OAuth consumer, but this is not possible for an app password. In case an app password doesn't have the necessary permissions, you can create a new one.
Is there any additional output from this API call, other than the 403 error code? Also, do you get the same error if you use another Bitbucket API endpoint, e.g. /2.0/repositories/{workspace}/{repo_slug}/src, with the same credentials?
Kind regards,
Theodora
Hi Theodora,
I am using an app password with maximum privileges. I was able to use the app password for other endpoints, not sure why I'm getting this error for the commits portion of PRs. I am able to get info on PRs, excluding commits,
Thank you for your attention and input!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Not a problem, I'm happy to help! I have checked our logs for pull requests API calls made by the Bitbucket user that has the same email as your community account, using an app-password and with status 403 for the last week, but my search doesn't show any results.
Could you please let me know the following:
1. Are you using for the authentication the Bitbucket account with the same email as your community account?
2. Can you consistently reproduce this, or is it an intermittent issue?
3. If this error occurs every time you use this endpoint, would it be possible for you to make a new API call with this endpoint when you have the chance, and let me know the date and time you made the call in UTC (you can use this to convert the time in UTC: https://savvytime.com/converter/utc), so I can check our logs again?
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your instructions!
1) Yes, I am using the same email account. However, for app auth I use my username instead of an email address - using an email address yields a 401 error. Using the username for this account successfully allows me to auth and retrieve PRs, except for the endpoint in question that is causing 403 error.
2) Yes, it is consistent.
3) I ran it just now. Sept 10, 2021 6:23 PM UTC. requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.bitbucket.org/2.0/repositories/<owner>/<repo slug>/pullrequests/38/commits/
- The <owner> is not my personal account, it is a work account to which I have access - for which I am able to access other end points.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thank you for the info. I have checked our logs, I can see the API calls made to https://api.bitbucket.org/2.0/repositories/<owner>/<repo slug>/pullrequests/38/commits/ with 403 status, but I'm afraid I do not see any additional info that could shed some light on why the error is occurring. I also don't see any issues with your access to this specific repo.
My suggestion would be the following:
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No luck again with a new app password.
I have also attempted similar api calls on my own personal account / repo, and still the api returns 403 errors. This leads me to conclude it is not a permissions issue, but an api issue. Looking closer at the doc/ref, I see that some of the end points require redirects, which may be causing issues with the bitbucket python module I was using. I therefore did a raw curl request with redirects, and it worked! I will just have to use curl for getting the commits and diffs, but I now have what I need.
This is what worked:
curl --user <user>:<pass> -L -s -XGET "https://api.bitbucket.org/2.0/repositories/<owner>/<repo>/pullrequests/<pr_id>/diff"
Thanks again!
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
Thank you for your reply.
I assumed that you were already using curl (my mistake, I shouldn't have made that assumption), so I didn't think of looking elsewhere.
For the pullrequests/<pr_id>/diff endpoint it makes sense, and the -L is needed in the curl command to allow the redirect. The pullrequests/<pr_id>/commits endpoint though doesn't redirect, so I'm not sure why there would an issue there. That being said, I am not familiar with bitbucket python module and the details of its implementation.
I'm glad that you figured this out and thank you for posting what worked for you!
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's my fault, I should have indicated the manner of my interaction with the API.
If I ever figure out the python issue, I'll make sure to post back.
Thanks,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.