Aleks G
Aleks G

Reputation: 57316

Merging bitbucket pull request via API

According to Bitbucket API documentation, I should be able to merge a pull request with POST to this url:

https://bitbucket.example.com/rest/api/1.0/projects/{projectkey}/repos/{repositoryslug}/pull-requests/{pullrequestid}/merge?version

Yet, whenever I try it, I receive response 409 Conflict and in the response, it contains this:

"message": "You are attempting to modify a pull request based on out-of-date information.",
"currentVersion": 0,
"expectedVersion": -1,

I tried passing 0 as the version number, -1 as the version number, omit version number altogether - the result is always the same. How can I get it to merge?

Upvotes: 3

Views: 9671

Answers (2)

Aleks G
Aleks G

Reputation: 57316

As it turns out, atlassian API documentation was a bit wrong (or unclear). I was doing everything correctly, but the version number needs to be passed differently. According to the docs, the format is

https://.../merge?version

Whereas the correct format is

https://.../merge?version=<version>

Upvotes: 7

Yuri G.
Yuri G.

Reputation: 4648

The version value should be the value from the response of the GET request as documented here

In addition you can check if the pull request can be merged by making a GET request to the merge endpoint

Upvotes: 0

Related Questions