Create /pullrequests endpoint api does not work as expected. It returns pull request creation link instead of opened pull requests link

Hi Guys,
I am developing a pipeline bot. This bot makes a REST call to the following endpoint with a payload. However, the endpoint returns a pull request creation link instead of an opened pull request link. When I tried the same request body and endpoint with Postman, the pull request was successfully created.

Endpoint: https://api.bitbucket.org/2.0/repositories/owner/repo/pullrequests
method: POST
Headers:

{
Authorization: Bearer $mytoken
Content-Type: application/json
}

Payload:

 {
            "title": "Localization AI",
            "description": "added new translations",
            "source": {
                "branch": {
                    "name": "localize-ai-1687650256680"
                }
            },
            "destination": {
                "branch": {
                    "name": "master"
                }
            }
        }

Hi @harunkelesoglu,

I just tried to create a pull request with the POST Create a pull request:

curl https://api.bitbucket.org/2.0/repositories/<workspace>/<repository>/pullrequests \
    --header 'Authorization: Bearer <repository-access-token>' \
    --request POST \
    --header 'Content-Type: application/json' \
    --data '{
        "title": "My Title",
        "source": {
            "branch": {
                "name": "<source-branch>"
            }
        }
    }'

(I’ve used a response access token for the REST API authentication/authorization)

And the response body contains the id of the pull request as the id field.
In my case the pull request id for this repository was 1. This is the start of the response:

{"comment_count": 0, 
"task_count": 0, 
"type": "pullrequest", 
"id": 1, 
"title": "My Title"

Are you sure you only get the URL? Have you tried with the command line directly in your environment?

Cheers,
Caterina

Hi @ccurti, Thanks for your response. Yes i’ve already made rest-call with postman and it worked. The problem is that, when i made a rest-call to the endpoint in ci/cd pipeline it returns pull request creation link instead of pullrequest created. Have you ever tried create pull request in bitbucket pipeline? When you try it you will understand what i mean

Hi @harunkelesoglu,

I just tried the same command within a Bitbucket pipeline and I still get the same format for the output:

This is the bitbucket-pipelines.yml file:

image: atlassian/default-image:3

pipelines:
  default:
    - step:
        name: 'Build and Test'
        script:
          - echo "Creating a pull request..."
          - echo $BITBUCKET_REPO_OWNER
          - echo $BITBUCKET_REPO_SLUG
          - curl --request GET --url "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/pullrequests" -H "Authorization:Bearer ${BEARER_TOKEN_1}" --header 'Accept:application/json'
          - ./pipelines-script/curl-bash.sh

And the curl-bash.sh file:

#!/bin/bash

curl --request POST "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/pullrequests" \
  -H "Authorization: Bearer ${BEARER_TOKEN_1}" \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --data "$(echo -e '{
                "title": "My Title",
                "source": {
                  "branch": {
                    "name": "test-pipeline"
                  }
                }
              }')"

I originally wanted to have the command directly in the bitbucket-pipelines.yml file but after some time I decided it would be easier to set up, maintain and read it if it was a separate bash file.

Caterina

1 Like