How to read 2398 records in multiple REST API GET calls

Arka Banerjee1
Tera Contributor

Hi All,

 

I have a requirement to read 2398 records in a GET call from a third party(IIQ) table, but they have a restriction that at a time only 500 records can be read. PFB URL

something?startIndex=1&count=500&filter=application.displayName%20eq%20%22something%22
 
Now in here I have to read 1 to 500 in 1 call, 501-1000 in another and so on and that is controlled in that startindex and count of the URL(startindex being starting index of the record and count being no of records to be fetched starting from the start index) the total records(2398 in this case) is there in the responsebody JSON in a key so I can get that via my script. Now how to loop through all these 2398 records, 500 at a time. 
 
Any help would be greatly appreciated
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Arka Banerjee1 

if they are supporting pagination you can do this

1) first make an API call to know the total count

2) then divide it by 500 so that you get to know how many times you need to hit the API

Example: if you get count as 1800 then it means you need to do 4 times

1 to 500, 501-1000, 1001-1500, 1500-1800

you will run loop and then you will get to know the startIndex

what script did you start with?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

jaswalvishal106
Tera Expert

@Arka Banerjee1  were you able to achieve your requirement? If yes, then can you please share the logic/code.