Bitbucket Server REST API for merging Pull Request fails

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Problem

When merging a Pull Request using the REST API, a similar JSON response is returned by the server:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "errors": [ { "context": null, "message": "You are attempting to modify a pull request based on out-of-date information.", "exceptionName": "com.atlassian.stash.pull.PullRequestOutOfDateException", "currentVersion": 0, "expectedVersion": -1, "pullRequest": { "id": 1, "version": 0, "title": "Test", "description": "asdf", "state": "OPEN",

Diagnosis

Diagnostic Steps

  • From the JSON above, the version value-pair (line 11) of the sample Pull Request is 0. That is a mismatch with the version parameter you're sending on your REST call.

Cause

According to the Bitbucket Server REST API documentation, the default value for version is -1. You need to specify the right value during your REST call.

For more info about this error, please check BSERV-11108 - Declining a Pull Request for the second time in a row throws "You are attempting to modify a pull request based on out-of-date information." BUG.

Solution

Resolution

  • You can use the version informed by the JSON sample above. In that case, it is 0.

  • If you are unable to identify the version, you can run the following command to find out the version of a Pull Request:

    • If for some reason you can't see the version of the Pull Request above, it's possible to run the following curl command to get the Pull Request version.

      1 curl -H "Content-Type:application/json" -H "Accept:application/json" --user admin:admin -X GET http://<Your_Stash_URL>/rest/api/1.0/projects/<PROJECT_ID>/repos/<REPO_ID>/pull-requests/<PR_ID>/
  • To fix the reported error, please run the following curl command, passing the version parameter as part of the URL:

    1 curl -H "Content-Type:application/json" -H "Accept:application/json" --user admin:admin -X POST http://<Your_Stash_URL>//rest/api/1.0/projects/<PROJECT_ID>/repos/<REPO_ID>/pull-requests/<PR_ID>/merge?version=0

If you are running your own script (i.e. Python or any other language), please run a test with the curl calls above. We've seen errors in scripts causing similar issues and curl is always a spot on way to solve those.

Updated on April 16, 2025

Still need help?

The Atlassian Community is here for you.