Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a pull request in a Bitbucket using api 1.0

I am trying to create an automation pipeline and in that, I want to create a pull request in bitbucket from my jenkins job. I found some document where I can create a pull request using rest api. But that is for api 2.0. I have old bitbucket and I am not sure which api version I have to use.

Thanks,

like image 554
Mithil Amin Avatar asked Jan 01 '26 01:01

Mithil Amin


1 Answers

You can create a pull request in Bitbucket using the REST API 1.0 doing the following:

curl -s --user USER:PASS --request POST --data @- --header Content-Type:application/json https://BITBUCKET-SERVER/rest/api/1.0/projects/TO-PROJECT/repos/TO-REPOSITORY/pull-requests << EOF
{
    "title": "SOME-TITTLE",
    "description": "SOME-DESCRIPTION",
    "state": "OPEN",
    "open": true,
    "closed": false,
    "fromRef": {
        "id": "refs/heads/FROM-BRANCH",
        "repository": {
            "slug": "FROM-REPO",
            "name": null,
            "project": {
                "key": "FROM-PROJECT"
            }
        }
    },
    "toRef": {
        "id": "refs/heads/TO-BRANCH",
        "repository": {
            "slug": "TO-REPO",
            "name": null,
            "project": {
                "key": "TO-PROJECT"
            }
        }
    },
    "locked": false,
    "reviewers": [
        {
            "user": {
                "name": "REVIEWER"
            }
        }
    ]
}
like image 59
Marcelo Ávila de Oliveira Avatar answered Jan 05 '26 07:01

Marcelo Ávila de Oliveira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!