How to filter by Datetime on Jira Align API

Still need help?

The Atlassian Community is here for you.

Ask the community



Summary

According to this documentation, Jira Align API has a limitation where it is not possible to filter by time in datetime fields:

Trying to eq to match the time will not work here. You can only gt, lt, ge & le on the date itself. Additionally, you do not need to encode the hyphens and colons in the Date/Time field.

The main problem will be that the Jira Align API will ignore the "Time" passed in the API endpoint.

Then, it is necessary to use odata features to workaround this limitation on Jira Align API. For that, we can use cast as described in this documentation.

Environment

Jira Align

Solution

If a user wants to filter a specific date and time using Jira Align API, the API will ignore the "time". For example,

Trying to filter values greater than the day "01-JUL-24" and with the time "10:30", the user should pass in the API the datetime like "2024-07-01T10:30:00Z". So due to the limitation of Jira Align API,  the Jira Align API will not understand "10:30:00Z" to be filtered, then the Jira Align API will interpret it like "00:00:00Z".

Therefore, datetime is a type for odata, and as a solution, we must use a cast to split the values into the command $filter.

To illustrate, let's use the “createDate” field as an example of the endpoint /rest/align/api/2/users and use "2024-07-01T10:30:00Z" as the "time" filtered with a value greater than 10:30.

We would need to cast the hour and the minute and then use ge and gt commands in the API endpoint.

The example of the code is:

/rest/align/api/2/users?$filter=( (  createDate ge 2024-07-01T10:30:00Z and hour(createDate) ge 10 and minute(createDate) gt 30 ) ) 
  • Note that API will cast the createDate attribute, splitting the hour from there, and will be compared with 10.
  • The same happens with minutes, which will isolate the minute from createDate and will compare with the value 30.


With this approach, we will be able to filter by datetime fields. It can also be included in endpoints with pagination, like using $top and $skip, and other commands, like $select, as described below:

/rest/align/api/2/Releases?$top=100&$skip=0&$select=id,title,endDate&$filter=(endDate gt 2023-01-06T00:00:00Z and endDate lt 2023-01-07T00:00:00Z) 
Last modified on Jul 5, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.