Use REST API to return results of filter?

Rune Hellem April 19, 2017

While trying to find a workaround for the problem I have as described in the question How to proper write complex JQL-query for the REST-api (double qoute problem for custom fields) I was hoping that it was possible to trigger a filter using the REST API and by that getting the same results returned as I would by triggering the same JQL search using the API. And by doing so, not needing to bother about escaping qoutes and all that stuff.

But reading the documentation https://docs.atlassian.com/jira/REST/server/ I have not been able to figure out if this is possible.

Am I right when concluding that I cannot get the results of the filter using the REST API, it is only possible to create/update etc. the actual filter, not getting the results.

3 answers

4 votes
David Nickell April 26, 2019

I've used some Excel VBA scripts for quite some time to accomplish what is being asked ... but it takes a couple of REST Calls.  Maybe this solution will give you some pointers

Summary:

  1. Auth Call : /rest/auth/1/session
  2. Get Filter Definition : /rest/api/2/filter/inFilterId
    • From this you will want the "jql" property)
  3. Field List -- you have two options
    • Hard code your own list
      • This is probably best for consistency and certainly the easiest of the two methods
    • Get the filter's field list :  /rest/api/2/filter/inFilterId/columns
      • using the filter's definition is a bit trickier as you have to walk the JSON structure to grab the field names.
  4. Actual Filter Results using Search (as a Post Call) : 
    • create a payload string  =
      • {  "jql":"jql from filter in step 2",
      • "startAt":0,
      • "maxResults":1000
      • "Fields":[FieldList]  }
    • Make a Post Call for Search: /rest/api/2/search

.. and now that I see this question is over a year old, I'll stop here :-)  

You will need a JSON Parser to interpret the results of each call.   If you're stuck and think I can help, leave a reply here.  I assume Atlassian will send me a notification.  (or reach me at David@davidnickell.com)

saurabh tarkar July 2, 2020

Hey David, 

Thanks!

I tried the above method and it worked, but when in step 3 when I am trying pass the columns name (field list ) from point 3.2, its not giving the response, the columns I am trying to retrieve data are:

{code:json}

{
"label": "ESU Summed and current Epic Sum Up information",
"value": "customfield_17205"
},
{
"label": "ESU Time Progress",
"value": "customfield_17207"
},
{
"label": "ESU Time",
"value": "customfield_17206"
}

{code}

Can you help me with this issue?

Is there any way we can use search using the filter rather than jql so that we can access the columns also?

0 votes
Joe April 23, 2018

I have the same problem, if I add a saved filter in JIRA like this:

...

CURLOPT_URL => $this->jiraServer . '/rest/api/latest/search?filter=59400',

...

it returns nothing.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 19, 2017

It is possible, the example you have probably seen at https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-query-issues works fine - it returns a list of issues that match the filter you give it.

There's a working example for both get and post on that page, and I suspect you are right about the post being slightly easier to form on a Windows box.

I'm afraid the "workaround" for the problems you're having is simply that you need to get the escaping correct.

Rune Hellem April 19, 2017

Nic - not sure if I follow - yes, I have seen the examples, but if I'm not totally mistaken they are all based on sending a JQL-search string. So I do not fully understand when you say "...it returns a list of issues that match the filter..." But, if you by filter mean JQL search string and not a saved filter in JIRA I do follow. And based on the last comment I do think that you mean just that.

Like Andrew Stanton likes this

Suggest an answer

Log in or Sign up to answer