Mithil Amin
Mithil Amin

Reputation: 207

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,

Upvotes: 3

Views: 2762

Answers (1)

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"
            }
        }
    ]
}

Upvotes: 6

Related Questions