REST API - 'order by' param is ignored

Saeed May 18, 2021

Jira Cloud

Issue:

REST API is ignoring 'order by' parameter. Following return result in the same order. Filter is: Key IN (PROJ-1, PROJ-2, PROJ-3). Sorting on other fields is ignored as well. Return result is always sorted on descending Key.

  • zzz.atlassian.net/rest/api/3/search?jql=filter=12345&orderBy=key&fields=key
  • zzz.atlassian.net/rest/api/3/search?jql=filter=12345&orderBy=-key&fields=key

Tried this format as well. Same result.

  • zzz.atlassian.net/rest/api/3/search?jql=filter=12345&order+by+key+ASC&fields=key
  • zzz.atlassian.net/rest/api/3/search?jql=filter=12345&order+by+key+DECS&fields=key

Documentation does not mention order as an option. Has this been deprecated or I am making an incorrect request? How can I sort on Key?

Using JQL directly (instead of filter=12345) returned the same result.

Thank you.

1 answer

0 votes
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2021

Hi @Saeed 

I haven't used a filter in an API query, but I feel the issue might be that the sorting should be in the filter itself. Your orderBy statement isn't part of the jql= section and the API call for search doesn't (and never did) support orderBy.

So I believe there are 2 ways to correct this :

  1. Add the orderBy statement into the filter itself
  2. Use the actual JQL query (including orderBy) in the API call
Saeed May 19, 2021

Thank you @Warren. Defining sort key/order in the saved filter is ignored as well. Jira server version ignores order in the saved filter and it is required adding it to the GET params. This, on server version, has worked for the past 4 years for us. We have moved from server to cloud and that does not work anymore.

Per your suggestion, I used the JQL directly in the call. That worked. However, it is not a viable option for us since the saved filter is used in a few places and changes regularly.

One more observation: Using the same saved filter in Google Docs's Atlassian add-on works fine.

I would appreciate all suggestions.

Saeed May 19, 2021

@Warren - Resolved.

"=" in filter=12345 must be encoded.

ORDER BY in GET overrides the one in the saved filter (if any). Correct behavior IMO.

  • Does not work:
    zzz.atlassian.net/rest/api/3/search?jql=filter=12345&order+by+key+ASC&fields=key
  • Works:
    zzz.atlassian.net/rest/api/3/search?jql=filter%3D12345&order+by+key+ASC&fields=key

To be on the safe side, I'm now encoding the entire parameter instead of using +

zzz.atlassian.net/rest/api/3/search?jql=filter%3D12345%20ORDER%20BY%20key%20ASC&fields=key

Like Dan Muldoon likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events