Bitbucket Server REST API for merging Pull Request fails

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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

Problem

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

{
    "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 - Getting issue details... STATUS BUG.

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.

      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:

    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.

Last modified on Mar 23, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.