Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Declining a pull request through REST api?

maddy302 March 6, 2020

I am trying to decline a pull request based using Bitbuket Server api.

This is the uri formed is and I am performing a Post- 

/rest/api/1.0/projects/{project}/repos/{repo_slug}/pull-requests/{pr_id}/decline/?{version}

 

I referred https://docs.atlassian.com/bitbucket-server/rest/6.10.1/bitbucket-rest.html#idp285

But I always get the error - 

{u'errors': [{u'context': None, u'message': u'You are attempting to modify a pull request based on out-of-date information.', u'expectedVersion': -1, u'currentVersion': 1, u'exceptionName': u'com.atlassian.bitbucket.pull.PullRequestOutOfDateException', u'pullRequest': {u'closed': False, u'reviewers': [], u'state': u'OPEN', u'toRef': {u'id': u're.....

 

What am I doing wrong? My u'currentVersion provided though call is 1 and the PR's version is also 1 .

3 answers

1 accepted

1 vote
Answer accepted
maddy302 March 6, 2020

So, here's the URI format of the API call to decline - 

/rest/api/1.0/projects/{project}/repos/{repo_name}/pull-requests/{pr_id}/decline?version={version}&pullRequestId={pr_id}

 

This worked in Postman and hopefully works in python requests as well.

jensim February 8, 2021
# I was able to fight the XSRF-issues and other problems passing an empty json object to the endpoint

pr_url="https://bitbucket.example.com/rest/api/1.0/projects/${project_key}/repos/${repo_name}/pull-requests/${pr_id}"
curl -s -f -u "$(whoami)" -X POST -d '{}' -H 'Content-Type: application/json' "${pr_url}/decline?version=${version}"
0 votes
Alex Bondarev December 6, 2023

that works for me in PowerShell

$declineUrl = "https://api.bitbucket.org/2.0/repositories/$workspace/$repo_slug/pullrequests/$pull_request_id/decline"
$bbPrDecline = Invoke-RestMethod -Method Post -Uri $declineUrl -Headers $headersCloud

0 votes
Edwin Kyalangalilwa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2020

Hi @maddy302 ,

Please confirm your post URI.

It should be

/rest/api/1.0/projects/{project}/repos/{repo_slug}/pull-requests/{pr_id}/decline?{version}

in the above it has a slash after decline

/decline/?{version}
maddy302 March 6, 2020

I was using python to decline a PR. You are right, I added an extra slash.

But before I make changes to my script, I am now trying if I am doing it correctly via postman.

 

I added a bearer token, in postman Authorization Tab.

POST - https://{bitbucker-server}/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/183/decline?version=0
https://{bitbucket-server}/rest/api/1.0/projects/{project}/repos/{repo}/pull-requests/183/decline?0

{project} and {repo} are replaced by the actual data.

I am able to perform a get request, but the POST give me an exception XSRF check failed in POSTMAN,

via python i get exception - A big json response, below is gist (an older PR whose version was 1)
{'context': None, 'message': 'You are attempting to modify a pull request based on out-of-date information.', 'expectedVersion': -1, 'currentVersion': 1, 'exceptionName': 'com.atlassian.bitbucket.pull.PullRequestOutOfDateException'
maddy302 March 6, 2020

I also observe expectedVersion as -1. 
And in general -1 means, something pretty bad has happened. Exception on Atlassian's end?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events