Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Declining a pull request through REST api?

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 .

2 answers

1 accepted

1 vote
Answer accepted

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}"

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}

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'

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
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

184 views 2 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you