API - How can i get a list of records within a date range using API's?*

thiraj
Tera Contributor

Hi Team,

I want to use API to get a list of records within a set date range. I tried a few ways and queries but it did not seem to work.

Here is what i did -

Tablename - Incident

sysparm_query - sys_created_onBETWEENjavascript:gs.dateGenerate('2016-11-20','00:00:00')@javascript:gs.dateGenerate('2016-11-29','12:59:59')

The following is the request url i get after i process the API.

I ran the URL in POSTMAN but it gives me an error.

What is wrong with what i did and how can i fix it to get all the records within the date range i specify.

All help is appreciated.

Thank you

1 ACCEPTED SOLUTION

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Hi Thiraj,


I always recommend utilizing the REST API explorer combined with list queries.


When you build the query you are looking for in a list, you can right click it to copy the query.


Screen Shot 2016-11-29 at 2.53.02 PM.png


Then paste that query into the API explorer GET query field,


Screen Shot 2016-11-29 at 2.53.24 PM.png



and click a code sample (Python) to see the formatted end point: url = 'https://mscmobilitytest.service-now.com/api/now/table/incident?sysparm_query=opened_at%3E%3Djavascri...'



Finally, ensure you are sending the right basic auth credentials.


View solution in original post

1 REPLY 1

darius_koohmare
ServiceNow Employee
ServiceNow Employee

Hi Thiraj,


I always recommend utilizing the REST API explorer combined with list queries.


When you build the query you are looking for in a list, you can right click it to copy the query.


Screen Shot 2016-11-29 at 2.53.02 PM.png


Then paste that query into the API explorer GET query field,


Screen Shot 2016-11-29 at 2.53.24 PM.png



and click a code sample (Python) to see the formatted end point: url = 'https://mscmobilitytest.service-now.com/api/now/table/incident?sysparm_query=opened_at%3E%3Djavascri...'



Finally, ensure you are sending the right basic auth credentials.