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 .
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.
# 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}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.