Using REST API with Servicenow

sanjaydhonde
Kilo Contributor

I have few questions, It would be great if someone could answer them.

  1. How to fetch the incidents sorted by time?
  2. One REST API query returns approx. 501 Incidents. How to get the next set of incidents? [required for pagination]
  3. REST API to create/update/delete/view Knowledge ? Any Documentation?

Pradeep Sharma

1 ACCEPTED SOLUTION

jose_valle
ServiceNow Employee
ServiceNow Employee

Hi Sanjay,



For pagination, you can make use of the sysparm_offset and sysparm_limit parameters.




For example the following will retrieve 5 records (sysparm_limit=5) in the record set starting from the beginning (sysparm_offset=0) of the record set.



/api/now/v1/table/incident?sysparm_limit=5&sysparm_offset=0&sysparm_query=active=true^ORDERBYnumber



The get the next 5 records, you would simply increment the value of sysparm_offset by the value of your sysparm_limit



/api/now/v1/table/incident?sysparm_limit=5&sysparm_offset=5&sysparm_query=active=true^ORDERBYnumber



Another thing that helps is that you will actually get a link header in the response that provides the urls to first,prev,next and last pages based on values used for sysparm_offset and sysparm_limit. so you might just look into that to get the url to use to get the next page.



Hope this helps!


-Jose


View solution in original post

7 REPLIES 7

Thanks Jose.


I always receive same set when using offset it does not move to next records but still return same first set

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Sanjay,



Consider marking the question as answered, or marking replies as helpful as appropriate.


Or ask further questions or tell us what solution you found.


This will add value to Community Members reading this thread.



Best Regards



Tony