Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to add label to pull request via rest api?

akota December 12, 2018

Hi,

I can add a comment to pull request using rest api like this

curl -u "username:password" -H 'Content-type: application/json' -X POST https://bitbucket.abc.com/rest/api/latest/projects/SNDBX/repos/testing/pull-requests/1/comments -d '{"text":"mycomment"}'

Is there anyway to add a label to pull request ?

 

2 answers

1 accepted

2 votes
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 12, 2018

Hi Amulya,

Bitbucket Server doesn't currently have labels for pull requests. You can get them by using a plugin like the free Pull Request Labels one, but this doesn't provide an API endpoint.

We do have an open feature request to add pull request labels natively in Bitbucket Server. Presumably that would come with an API endpoint. If that's important to you, I suggest watching and voting on that issue!

Cheers,
Daniel

akota December 14, 2018

Thank you Daniel for your reply. 

Sanjay Pant December 2, 2019

Any update from Bitbucket on this?

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2019

Hey @Sanjay Pant !

The suggestion ticket is still listed as gathering interest. For more information about how Atlassian prioritizes feature requests made on jira.atlassian.com, check out this Community post. Keeping an eye on the ticket directly by watching it is the best way to stay up to date on the latest information. For your convenience in receiving this reply for email, here's a link to that feature request again: https://jira.atlassian.com/browse/BSERV-10715

Cheers,
Daniel

Like # people like this
Mark Bailie
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 26, 2020

If you use the Free Pull Request Labels by Reconquest there is a rest endpoint you just need to do a little digging to work it out (I couldn't find anything in the docs), here is what I've managed to work out;

 

To Read Labels

Method: GET

Headers:

Authorization: Bearer XYZ

URL: http://<insert_host>/rest/io.reconquest.bitbucket.labels/1.0/<insert_project>/<insert_repo>/pull-requests/1

Response: { "labels": [ "TEST_LABEL" ] }

 

To Write Labels

Method: POST

Headers:

Authorization: Bearer XYZ

X-Atlassian-Token: no-check

URL: http://<insert_host>/rest/io.reconquest.bitbucket.labels/1.0/<insert_project>/<insert_repo>/pull-requests/1

Post Data (x-www-form-urlencoded):

name=LABEL_NAME_HERE

Response: { "success": true}

 

Hopefully useful... 

Azfar Masut
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.
February 18, 2021

@Mark Bailie can you share how you are able to get these API? I'm trying to do a delete through the API as there is a UI bug for that add-on where the delete button is bled out/hidden to the side of the screen due to a very long label

Mark Bailie
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 18, 2021

@Azfar Masut I just took at look at what the UI was doing in the Web Inspector. I've had a very quick look at deletes and this is what I can see, fair warning though I've done absolutely no testing around this at all;

 

Method: DELETE

Headers:

Authorization: Bearer XYZ

URL:

http://<insert_host>/rest/io.reconquest.bitbucket.labels/1.0/<insert_project>/<insert_repo>/pull-requests/1

 

The HTTP response code then returns 200 for success. You'll probably need to play around with that to make it work, but it looks like it's the bones of what's needed :)

Like Azfar Masut likes this
1 vote
Sean Manwarring _Izymes_
Atlassian Partner
September 21, 2022

Hi Akota!

It is certainly possible to add a label to pull requests via rest API. You may be interested in one of our apps Organizr for Bitbucket!

Organizr will allow you to view and search by pull request 'label(s)', 'state', 'duedate', 'reviewer'(s), 'project', 'target' branch(es), any 'text' and 'author'(s) - for example "state=open & duedate <= 2016-Aug-23 & label IN (release_1, urgent) & text ~ junit" across the entire Bitbucket instance.

Here is an example of how labels are displayed and how they could be searched for (filter bar at the top);

Screen Shot 2022-09-22 at 8.31.51 am.png 

Here is a link to labels API spec
Line 242 of the source file in izymes-support organizr-public-apis

If you would like to suggest any additional functionality or need other support, we would love to hear from you

Happy Coding!

Sean

// Izymes 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events