Query REST API to find Incident which were updated in last 7 days

eyal_nscale
Kilo Contributor

I need to create a query that find Incidents that were updated in the last 7 days in using the rest API.

The documentation doesn't show how to do that. but when i use the UI i see a batch controller being used and passing something like:

{"query": {"and": [{"fieldName": "UpdatedOn", "operator": ">", "value": "...."}]}}

How do i construct the query programmatically against the rest API?
3 REPLIES 3

adityahubli
Tera Contributor

Hello @eyal_nscale ,

In servicenow there is OOTB module rest api explorer , first run your query on incident table filter then copy that query from that and paste in rest api explorer sysparm_query  . mentioning some screenshots . 

 

 

 

Screenshot (25).png

 

 

w1.pngw3.pngw4.png

 

If this helps you mark it as helpful and accept as solution.

Regards ,

Aditya

Hello @eyal_nscale ,

If above answer helps you then mark it as helpful and accept as solution.

Regards,

Aditya

VaishnaviK43271
Tera Contributor

You construct the query by putting an encoded query string into the sysparm_query parameter,

for example:
/api/now/table/incident?sysparm_query=sys_updated_on>=javascript:gs.daysAgoStart(7)

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for.

Thank You