Forums

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

JQL query to fetch data based on dynamic date passed in updated column

Vikas jagadale September 28, 2020

I want to fetch Incremental data based on the updated column, so the date passed value will be dynamic but in static format (YYYY-MM-DD)

Before issuing a GET Request I am doing URL encoding that works if the value of updated is passed as 1900-01-01 but for any other date like 2020-09-26, it returns the incorrect number of records, using encoded request, however for the nonencoded request it gives the expected result.

Also, I want to fetch results in pagination so I am using startAt and maxResults parameters

Non-Encoded request:

/rest/api/2/search?fields=fields=id,key,assignee&jql=project=XYZ AND updated>=1900-01-01&startAt=0&maxResults=50


Encoded request:

/rest/api/2/search?fields=fields=id,key,assignee%26jql%3Dproject%3DXYZ+AND+updated%3E%3D1900-01-01%26startAt%3D0%26maxResults%3D50


Is there a way to create an Encoded request to support any date?

1 answer

0 votes
Niranjan
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.
September 28, 2020

Is this not working

/rest/api/2/search?fields=id,key,assignee&jql=project%3DXYZ%20AND%20updated>%3D2020-09-26&startAt=0&maxResults=50  

 

only fields= should be used I guess

Vikas jagadale September 28, 2020

Yes, my bad I corrected that. Actually, the problem is with date range like I had mentioned it's not picking a dynamic date

Example, 
The below-encoded request works perfectly if updated>=1900-01-01

rest/api/2/search?fields=id,key,assignee%26jql%3Dproject%3DXYZ+AND+updated%3E%3D1900-01-01&startAt=0&maxResults=50

But if updated>=2020-09-26 then also it returns the same number of total rows.

rest/api/2/search?fields=id,key,assignee%26jql%3Dproject%3DXYZ+AND+updated%3E%3D2020-09-26&startAt=0&maxResults=50

Niranjan
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.
September 28, 2020

When you provide a static value, you cannot expect it to take dynamic values for dates. Can you try with the query as given below?

/rest/api/2/search?fields=id,key,assignee&jql=project%3DXYZ%20AND%20updated%20>%20startOfDay()&startAt=0&maxResults=50

 

The reason why it works for 1900-01-01 is that you may have too many records updated after 1900, but which is not the case for 2020-09-26 and so pagination may not display results as you would like to. BTW , how many records do you get when you filter issues with updated>2020-09-26?

Vikas jagadale September 28, 2020

So without URL Encoding, If I pass the updated value as 1900-01-01 then I get a total 38626 records and if I pass the updated value as 2020-09-26 then I see a total 1131 records which is expected value

rest/api/2/search?fields=id,key,assignee&jql=project=XYZ AND updated>=2020-09-26&startAt=0&maxResults=50


Seems something wrong with URL encoding
And I did try Request which you gave its working but not giving the expected result its returning 756 records only. Also, I prefer to pass hardcoded date like 2020-09-26 rather than using function startOfDay()


Suggest an answer

Log in or Sign up to answer