How to call pagination wise records throug REST API

Nitin Rout
Kilo Explorer

Hi Experts,

 

I want to make a rest message call from third party where we can only retrieve 200 records at a time. They have 2000 records in total. My concern is how to paginate the url mutliple times when calling the rest API by scheduled job.

Ex: https://test.com/test/api/v1/data/details?.full=true&.firstResult=0&.maxResults=200

https://test.com/test/api/v1/data/details?.full=true&.firstResult=200&.maxResults=200

https://test.com/test/api/v1/data/details?.full=true&.firstResult=400&.maxResults=200

and so on....

I have checked many solutions but can not think how to use the solution.

Can anyone please guide me where I can use the query or how to achieve this ?

Any help would be really appreciated. 

 

Thanks,

Nitin

8 REPLIES 8

Pranesh072
Mega Sage
Mega Sage
  • sysparm_limit: to define how many records you get in one call (10000 by default) 
  • sysparm_offset: to define the records to exclude from the query 

Have you tried this one ?

 

https://community.servicenow.com/community?id=community_question&sys_id=03dc0477dbd66f002e8c2183ca96...

Hi Pranesh,

 

I have already gone through this article. But I have no idea where to define the script in the rest message. For your information it is not a scripted rest API.

If I will use the scripted rest API, then how should I call the rest message from the scripted rest API ?

I am not getting any idea on this as I am new to rest API.

Oh, you want to use it in Rest message.

 

Is there anyway you can get the total number of records? 

Anil Lande
Kilo Patron

Hi,

When you make an API call it returns the page size or related attributes in a response. You need to repeat same query with page offset to get next page records.

Repeat loop based on no of pages and make API call again with page value to get next page information.

 

Thanks,
Anil Lande 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande