How to add version numbers to all Jira issues in a release?
Asked by shaulbehr:

I have Jira, Bitbucket Server, and Bamboo.

When I make a release, I would like automatically to stamp the release number as the Fix Version for all Jira issues detected in the release.

I found REST API endpoints for Jira that seems to be appropriate:

```
POST: /rest/api/2/version (to create a version)
PUT: /rest/api/2/issue/ISSUE-1 (to update the issue with new fixVersion)
```

But I can't find any REST API that gets a list of Jira issues related to a release.

I am flexible; we can work with the issues related to a given commit when Bamboo does the build, or we can look at the issues included when Bamboo makes a new release (i.e. since the last release). Either way will work for me.

What's the API to use?


Answers:
author: Warren
body: Hi [@shaulbehr](/t5/user/viewprofilepage/user-id/664878)

Firstly, [this](https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/) is the server API documentation which will become your friend if you're doing any API work.

***/rest/api/2/search*** is probably the most flexible call for you to use, because you append ***?jql=*** and then use any JQL you like. It could be sprint= or fixVersion= or created\>"" - it's up to you to build a JQL which returns all items you're expecting.

comments: author: shaulbehr
body: Hi Warren, thanks for the reference!

I took a look at the [search fields available](https://confluence.atlassian.com/jiracoreserver073/advanced-searching-fields-reference-861257219.html), and there doesn't seem to be anything relating to either Git commits or Bamboo releases. I tried doing a search on the Jira website itself, and can't find anything relevant to search on. Did I miss something?

Anyway, I don't think the endpoint I want is going to be in the Jira API; it's more likely to be in Bitbucket or Bamboo. That's because my starting point is either a commit number (Bitbucket) or a release number (Bamboo), from which I want to retrieve the related Jira issues. I know it must be possible, because Bitbucket and Bamboo themselves show you very helpfully which Jira issues are linked to pull requests or new releases. I just need to find out what APIs they are using there.

Any ideas?


author: Warren
body: Hi [@shaulbehr](/t5/user/viewprofilepage/user-id/664878)

[This](https://docs.atlassian.com/bitbucket-server/rest/4.5.1/bitbucket-rest.html) is the Bitbucket server API and [this](https://developer.atlassian.com/bitbucket/api/2/reference/meta/filtering#query-repo) is (I think) the cloud version. I have used both to get me successfully using the Bitbucket API.


author: shaulbehr
body: So I found this API being called in Bitbucket:

```
/rest/jira/latest/projects/LS/repos/my-proj/pull-requests/3772/issues
```

That's the kind of endpoint I'm looking for, though it's not exactly right, because this gives the issues per pull request, whereas I want the issues per commit. This also must exist, because I can see it on the "commit" screen, as highlighted below:

![2019-07-11 13_48_04-LightSail _ API _ bfaf95ed9e0 - Bitbucket.png](https://community.atlassian.com/t5/image/serverpage/image-id/60300iA1413A4181754356/image-size/large?v=v2&px=999 "2019-07-11 13_48_04-LightSail _ API _ bfaf95ed9e0 - Bitbucket.png")

I looked in the developer tools and couldn't find the call that returns the issue numbers related to the commit, though.

What is the call?


author: shaulbehr
body: Got it! It's this one:

### /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/commits/{commitId} {#toc-hId-1083643573}

At the bottom of the response is:

```
"properties": {
  "jira-key": [
    "LIGAPI-4352"
  ]
}
```

Thanks for your help!


Tags: jira

jira-server

rest-api

server