
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2016 05:13 AM
Hello All,I want to limit
I want to limit query to 50 records at a time while making a GET call to Service Now. I have checked there is one parameter(sysparm_limit) by which I can limit the number of queries at a time but I want that if number of records are 10000 then it should get all the records but in 50 records per query fashion. Any idea how to achieve this.
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2016 09:49 AM
The idea of having sysparm_limit and link header is exactly to support this scenario. When you make your first call on load of page, you pass sysparm_limit =30 as query parameter.
With the response, you will get next, prev link in headers. when ever you scroll down, you make next call to get next 30 records using next and keep going
It is recommended to use ORDERBY so you don't get duplicate records because of changes in DataBase plan which might re order results causing duplicates
For eg. My initial request for 10 records looks like this
Response will have Link header
Link →
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="first",
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="next",
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="last"
If you see here there is link for rel=next, which gives you next 10 records. There are libraries out there which can parse this header elegantly to get proper links for next, first,last set of records.
In this case, we need to get 'rel=next' link and make subsequent request to get next 10 records
Response will have another set of headers with again next, prev link to get that set of records
Link →
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="first",
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="prev",
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="next",
<https://instance.service-now.com/api/now/table/sys_user?sysparm_limit=10&sysparm_query=ORDERBYsys_cr...>;rel="last"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 05:29 PM
Hey Adam-No, did not find any libraries (at least not on the platform I could refernce) to parse the response. I played with using regex to parse the responses, but ended up going in a different direction. Somewhat simplier.
I ended up writing an initial GET request to the return the count of records by retrieving the header X-Total-Count. Once I had the count, I ran another GET request and iterate through a loop till I had all the records.
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2020 03:42 AM
Which is the library to get ;rel="next", from header?
How can i extract ;rel="next", from header response?