20

I am writing a script (in Powershell if that matters) to deploy SQL code. Part of the logic that I want in the script is to have it check that the JIRA issue associated with the script is in the correct status prior to deploying (e.g. in my case that the issue status is "QE Certified".

I'm trying to use the JIRA REST API but so far have been unable to find a way to give me the current status of an issue. The closest I've found is to look at the transitions available for the issue:

https://docs.atlassian.com/jira/REST/5.2/#id251679

This doesn't give me the current status but I could figure it out from the available transitions. That seems a bit kludgy to me.

I was hoping there would be something like /rest/api/2/issue/{issueIdOrKey}/status that would just give me the current status of the issue.

What would be the best way to get the issue status via the REST API?

Thanks

user3570706
  • 225
  • 1
  • 2
  • 7

5 Answers5

39

You can use /rest/api/2/issue/{issueIdOrKey} and set the fields-parameter to restrict the returned data to the status field.

So your request would be:

/rest/api/2/issue/{issueIdOrKey}?fields=status
Vikdor
  • 23,934
  • 10
  • 61
  • 84
Seb
  • 1,721
  • 1
  • 17
  • 30
11

It can be achieved by using curl command.

Syntax:

curl -u username:password -X GET -H "Content-Type: application/json" 
     https://server-url/rest/api/2/issue/JRA-1?fields=status
Vikdor
  • 23,934
  • 10
  • 61
  • 84
Ramkumar D
  • 9,226
  • 2
  • 17
  • 18
7

Here is the sample request :

/rest/api/2/issue/HTP-55

HTP-55 is issue id.

Here is the part of the response which can be useful for you.

"status": {
  "self": "rest/api/2/status/3",
  "description": "This issue is being actively worked on at the moment by the assignee.",
  "iconUrl": "images/icons/statuses/inprogress.png",
  **"name": "In Progress",
  "id": "3"**
},
Vikdor
  • 23,934
  • 10
  • 61
  • 84
Hiren
  • 242
  • 1
  • 9
1

If you prefer using later Jira REST Java Client API (e.g. 4.0), following is the sample code.

private static final String JIRA_SERVER = "http://jiralab";

public static void main(String[] args) {
    try {
        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        URI uri = new URI(JIRA_SERVER);
        JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, "admin", "admin");
        getIssue(client, "ISSUE-1");
    }
    catch (Exception ex) {
    }
}

private static void getIssue(JiraRestClient client, String key) throws Exception {
    Promise<Issue> promise = client.getIssueClient().getIssue(key);
    Issue issue = promise.claim();
    System.out.println("Summary = " + issue.getSummary() + ", Status = " + (issue.getStatus() != null ? issue.getStatus().getName() : "N/A"));
}
PerseusBC
  • 151
  • 1
  • 5
1

Late to the thread, but useful nevertheless. The command leverages the power of jql.

Returns you the id, key and status fields of ALL items in a project. This is useful if you want to do some reporting, especially based on the status.

curl -u username:passwoorod -X GET -H "Content-Type: application/json" 'https://www.url.com/rest/api/2/search?jql=project=PROJ&fields=id,key,status'

Reference: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#request-18

Rakesh Gupta
  • 3,507
  • 3
  • 18
  • 24