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

Hi,

 

Where can I define the loop in the rest message. There is only the header and query parameters.

Could you please provide an example ?

 

Regards,

Nitin

Hi,

Can you please share sample JSON response?

And your API swagger definition where your API is documented.

 

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

Hi,

Below is the first line of the response when I am testing the rest message call.

 

<?xml version="1.0" ?>
<queryResponse last="199" first="0" count="1767" type="details" responseType="listEntityInstances" requestUrl="https://test.com/test/api/v1/data/details?.full=true&amp;amp;.firstResult=0&amp;amp;.maxResults=200" rootUrl="https://test.com/test/api/v1/data">

Hi,

As this API Return 200 record, and based on count (i.e 1767) you need to make multiple call to same API

For example.

1. Make a call to root API <"https://test.com/test/api/v1/data>

2. Parse response and your can get the first 200 records. Also store the count in soem variable and make further call until you get all records:

var totalRec = responsebody.count;  // i.e 1767
var receivedCount = 200;
while(receivedCount<totalRec){
// make another call to url = "https://test.com/test/api/v1/data/details?full=true&firstResult="+receivedCount+"&maxResults=200;
// make API call and parse next 200 records
receivedCount = receivedCount +199;
}

 

As you can see the result received has maxResults=200, you can try making API call with updated URL with value maxResults=2000.

Please check documentation for the same, same must be documented on 3rd part API documentation.

 

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