Endpoint: POST /2.0/repositories/{workspace}/{repo}/pullrequests/{id}/approve
Token type: api_token (ATATT)
Scopes configured: write:pullrequest:bitbucket, read:pullrequest:bitbucket
x-accepted-oauth-scopes: pullrequest:write ← formato viejo
x-oauth-scopes: write:pullrequest:bitbucket ← formato nuevo
Result: HTTP 400 Bad Request
The endpoint is not accepting the new API token scope format
even though documentation states write:pullrequest:bitbucket
should allow approving PRs.
Hi @Jesus Alejandro Cardenas Vilca
Without seeing the cURL request, 9/10 times the problem is the way that the authentication is being used.
Full instructions are below - please review these and let me know if you still encounter issues:
To start using API tokens with Bitbucket Cloud - you'll need to create the API token and specify the scope - this is mentioned in our deprecation documentation:
Click the gear cog icon, select Atlassian Account settings > Security tab > Create and manage API Tokens
Click Create API token with scopes and select Bitbucket Cloud
You’ll now need to define the scopes necessary for the API commands you’re intending to execute. A summary of these for common API operations is as follows - you can find more information on scopes in our API scopes documentation:
Repository Operations
GET (Read):
Scope: read:repository:bitbucket
Allows viewing repository data, including source code and configurations.
POST/UPDATE (Write):
Scope: write:repository:bitbucket
Allows modifying repository data (e.g., updating source, branches, tags, forking).
DELETE:
Scope: delete:repository:bitbucket
Allows deletion of repositories.
Pull Requests
GET (Read):
Scope: read:pullrequest:bitbucket
Allows viewing pull requests and commenting.
POST/UPDATE (Write):
Scope: write:pullrequest:bitbucket
Allows creating, updating, approving, declining, and merging pull requests.
Issues
GET (Read):
Scope: read:issue:bitbucket
Allows viewing, listing, searching, and commenting on issues.
POST/UPDATE (Write):
Scope: write:issue:bitbucket
Allows creating, updating, transitioning, and deleting issues.
Wikis
GET/POST/UPDATE/DELETE:
Scope: wiki:bitbucket
Provides both read and write access to wikis (view, create, edit, push, clone).
Snippets
GET (Read):
Scope: read:snippet:bitbucket
POST/UPDATE (Write):
Scope: write:snippet:bitbucket
DELETE:
Scope: delete:snippet:bitbucket
Pipelines
GET (Read):
Scope: read:pipeline:bitbucket
POST/UPDATE (Write):
Scope: write:pipeline:bitbucket
Perform the API command by using the API token with either of the sample commands below.
Example 1: The API token, along with your Atlassian account email, can be sent as login credentials. For example:
curl --request POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits' \ --user '{atlassian_account_email}:{api_token}' \ --header 'Accept: application/json'Example 2: Alternatively the API token can be sent in a HTTP Authorization header after the Bitbucket email and API token have been base64 encoded. For example:
my_credentials_after_base64_encoding=`echo -n '{atlassian_account_email}:{api_token}' | base64`
curl --request POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repository}/commits' \ --header "Authorization: Basic $my_credentials_after_base64_encoding" \ --header 'Accept: application/json'Cheers!
- Ben (Bitbucket Cloud Support)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.