Update pull request title

Hi,

My requirement is to attach a JIRA issue with pull request and one way I think is to specify the JIRA issue in the pull request title in stash. Can you please help me with the REST API to update the pull request's title with the JIRA issue?

Thanks 

2 answers

0 vote
Mikael Sandberg Community Champion Nov 28, 2016

Check out /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}, the Put method allows you to modify the title, just send in the new title to replace the existing one.

Thanks Mikael for quick response. I had tried with this REST API but facing below error:

The specified HTTP method is not allowed for the requested resource

This is the command I am using:

curl -X POST -u USERNAME:PASSWORD -H "Content-Type: application/json" -d '{"title":"PRT-7"}' https://HOSTNAME/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/29

Am I missing anything?

Thanks

Mikael Sandberg Community Champion Nov 29, 2016

You need to use PUT instead of POST, and you also need to include id, version, title, description and reviewers in your payload, not just the new title. Here is an example using Ruby:

def updatePullRequest(url, encode)
  put_request = { :id => 5,
                  :version => 42,
                  :title => "A change - updated via REST API",
                  :description => "A description"
                }
  
  RestClient.put url, put_request.to_json, {:Accept => 'application/json',
                                            :Authorization => 'Basic ' + encode,
                                            :content_type => 'application/json',
                                            :data => put_request}

Note that the version has to be the same as the one you get in reply when doing a GET.

Thanks Mikael. It worked perfectly fine after adding version.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 06, 2018 in Bitbucket

Do you use Bitbucket Cloud and Jira Cloud? If so, let us know!

Hi Community, I'm Julia and I'm on the Jira Software Cloud marketing team!  We're looking for companies or teams using Bitbucket Cloud and Jira Software Cloud. If your team fits the t...

87 views 3 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you