Forums

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

How can I get all Jira issues by one or more statuses within a specific project using the rest API?

David February 28, 2023

What I did so far:

  • Created an API token.
  • Connected to the API.
  • I retrieved all tasks within a specific project

I used the following endpoint:

rest/api/2/search?jql=project={{PROJECT}}&maxResults=3
This returned:
object(stdClass)[1]
  public 'expand' => string 'schema,names' (length=12)
  public 'startAt' => int 0
  public 'maxResults' => int 3
  public 'total' => int 95
  public 'issues' => 
    array (size=3)
      0 => 
        object(stdClass)[2]
          public 'expand' => string 'operations,versionedRepresentations,editmeta,changelog,customfield_10010.requestTypePractice,renderedFields' (length=107)
          public 'id' => string '00000' (length=5)
          public 'self' => string 'https://domain.atlassian.net/rest/api/2/issue/00000' (length=56)
          public 'key' => string 'xxx-000' (length=10)
          public 'fields' => 
            object(stdClass)[3]
              ...
      1 => etc...

What I want:

  • Total number of issues in a specific status in a specific project ideally with one API call. Example: I want the total number of issues within the project with the following statuses: "In Progress", "Signoff / Review" and "Staged/Completed"

Note: I have custom workflow and custom statuses. 

What I tried:

Several suggestions from the community forums and Stack but nothing worked.

Example:

rest/api/2/search?jql=filter=11111+and+status="In+Progress"&fields=id,key,status

https://synergix.atlassian.net/rest/api/2/search?jql=project="PROJECT_KEY"%20and%20(status="In Progress"%20or%20status%20=%20"Open")

What I am trying to do?

Currently the Jira Software UI does not have the ability to show total number of issues within my parameters. I need this information to generate reports and estimates.
I found the feature request for this on the forum but it's still in "Consideration" 

I am using PHP Curl.

2 answers

1 accepted

0 votes
Answer accepted
David March 1, 2023

Documentation needed to connect and query based on a custom workflow: Click here;

The solution:

project = PROJECT_ID AND (status="Staged / Completed" OR status = "Live / Closed")

Everything together:

$jira_token = "YOUR_API_TOKEN";
$jira_domain = "https://DOMAIN.atlassian.net";
$jira_user = "EMAIL@DOMAIN.com";

$jql = "project = PROJECT_ID AND (status=\"Staged / Completed\" OR status = \"Live / Closed\")";

$query = http_build_query([
"jql" => $jql,
"maxResults" => 3,
"fields" => "self"
]);

$jira_url = $jira_domain . '/rest/api/2/search?' . $query;
$jira_password = $jira_user .":". $jira_token;

// Do your Curl request...

$jira_issues = json_decode($result);

Explanation:

YOUR_API_TOKEN - More about it here.

PROJECT_ID - Or project key. More about it here.

DOMAIN - Your Atlassian domain.

EMAIL@DOMAIN.com - Your Jira account email.

 

Note: I suggest that you use this instead of building this from scratch.

David March 1, 2023

Some help for folks that are using a local env to test. This took me a while to figure out but you need CA certificates to use the API on WAMP or XAMPP.

Download here. 

There is plenty of help online on how to install it.

0 votes
Trudy Claspill
Community Champion
March 1, 2023

Hello @David 

Welcome to the Atlassian community!

Do you need to get this information through the API so that you can use the value somewhere else programmatically?

If you don't require that, then two ways you can get the count of issues matching a filter are:

1. Use an Automation Rule with a Lookup Issues action to retrieve the issues, and email yourself the count of issues using the smart value {{lookupIssues.size}}

2. Use the Two Dimensional Filter Statistics gadget on a Jira Dashboard.

David March 1, 2023

Hi @Trudy Claspill 

yes, I need programmatic access. I want to use this information on my reports dashboard.

Trudy Claspill
Community Champion
March 1, 2023

When you say nothing has worked, what are you getting? Is there an error message? Is the 'total' value in the returned object wrong?

David March 1, 2023

I appreciate you trying to help but I figured it out on my own. I posted the solution here to help someone else maybe trying to achieve the same.

Suggest an answer

Log in or Sign up to answer