Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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}"
0 votes
edwin Community Leader Mar 06, 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}

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 any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

493 views 5 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