Scipting Labels in Bamboo (for historic artifacts)
Asked by Tim Finch:

Hi,

We are looking to implement the Bamboo Global Expiry policy, but we have been using the tool for a number of years now.

We need to retrospectively apply labels across historic artifacts chosen by our development teams, before we implement the Global Expiry Policy.

Is there any pain free options for doing this? Scripts? Plugins? that would aid in applying labels across historic artifacts on mass?

Thanks


Answers:
author: Steffen Opel _Utoolity_
body: You should be able to achieve this via the [Bamboo REST API](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/), which supports adding/removing labels from plans/builds - relevant resources are:

* Verify/Apply labels across historic results  
  * [http://myhost.com:8085/rest/api/latest/result](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3559) \[[GET](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3562)\]  
    * [http://myhost.com:8085/rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber}/label](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3808) \[[GET](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3818), [POST](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3846)\]
    * [http://myhost.com:8085/rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber}/label/{labelName}](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3878) \[[DELETE](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e3883)\]
* (Optional) Manage/Retrieve plan labels to guide the retroactive result labeling
  * [http://myhost.com:8085/rest/api/latest/plan](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e1872) \[[GET](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e1875)\]
    * [http://myhost.com:8085/rest/api/latest/plan/{projectKey}-{buildKey}/label](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e2008) \[[GET](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e2015), [POST](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e2043)\]
    * [http://myhost.com:8085/rest/api/latest/plan/{projectKey}-{buildKey}/label/{labelName}](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e2063) \[[DELETE](https://docs.atlassian.com/atlassian-bamboo/REST/6.8.0/#d2e2073)\]

As usual, any REST client will do, I'm personally using the free edition of [Postman](https://www.getpostman.com/) to explore/test an API from the browser and [HTTPie](https://httpie.org/) for the actual implementation from the command line.

The Bamboo REST API supports both XML and JSON representations, and I think the former is the default, so make sure to request JSON by specifying "Content-Type: application/json" if you prefer this nowadays easier to work with format.

comments: author: Amol Kandurwar
body: [@Steffen Opel _Utoolity_](/t5/user/viewprofilepage/user-id/781567) I tried following the API doc and I am getting "HTTP Status 415 -- Unsupported Media Type, The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource." even if I am passing proper json data with application/json content type.

Request:

curl -X POST -H "Content-Type: application/json" -H 'authorization: Basic XXXXX' -d '{"name":"UTWeekly"}' https://\<Bamboo URL\>/rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber}/label

Also tried witth Postman tool and got the same result.

\<!doctype html\>\<html lang="en"\>\<head\>\<title\>HTTP Status 415 -- Unsupported Media Type\</title\>\<style type="text/css"\>h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}\</style\>\</head\>\<body\>\<h1\>HTTP Status 415 -- Unsupported Media Type\</h1\>\<hr class="line" /\>\<p\>\<b\>Type\</b\> Status Report\</p\>\<p\>\<b\>Message\</b\> Unsupported Media Type\</p\>\<p\>\<b\>Description\</b\> The origin server is refusing to service the request because the payload is in a format not supported by this method on the target resource.\</p\>\<hr class="line" /\>\<h3\>Apache Tomcat/8.5.39\</h3\>\</body\>\</html\>


author: Amol Kandurwar
body: Looks good