Sometimes the API service does not return all records in one big JSON body, but divides it to one or more pages instead. This is mostly the case with GET Multiple Records operations which return more than one record.
So let's say that the sample GET API Endpoint on URL https://test.api.com/v3/Customers from the GET Multiple Records example is returning paginated data. The JSON stays the same:
But the API is returning maximum of 10 records. If you ask for more than 10 records, you need to send separate API requests for each page (i.e. for 23 records you would need to send 3 requests for records 1-10, 11-20, 21-23).
Of course, the goal of setting up a pagination with RESTwithUS is not to be bothered with it at all. The application should send all needed page requests for you and you would process the result like you received one big JSON response with all records.
RESTwithUS is now supporting pagination by URL Parameters only.
With URL parameters pagination you have a fixed page size (e.g. 10 records per page) and you are asking for specific page using URL parameters. Sometimes the API even allows you to select the size of the page.
So let's say the pagination in the example endpoint works like this: https://test.api.com/v3/Customers?page=2&page-size=10. This means that you are asking for page number 2
and each page should contain 10
records.
The pagination is usually different for each API and you can find the details in the API service documentation.
To set this up in RESTwithUS select your operation from the list and open Details:
In the details settings first set Request Pagination field to URL Parameters
:
Now fill in the URL parameters settings in Pagination tab:
page
in the example).page-size
in the example). Some APIs have a fixed page size – in such a case leave the field blank.1
. Change this only in case the first page in the API response has different number (e.g. the numbering starts from 0
).If there is more than one page, RESTwithUS sends a request for each page in the background. You can check it in Batch Entries.
Endpoint URL
.If Log is enabled on the provider, then there will be a log entry or file for each page.
Some API Script functions do not work with paging properly (they just return results for the last page). The list includes COUNT_RESPONSE_MEMBERS_BY_JPATH, GET_RESPONSE_HEADER, GET_RESPONSE_HEADERS and GET_RESPONSE_VALUE_BY_JPATH.
If you need to process paginated result with code, you can use APIScript function GET_RESPONSE_JSON to get the list of all page's JSON body. Then use standard Business Central JSON objects to work with the page body.
//Go through JSON data of all result pages
var
AllPagesBodyList: List of [Text];
i: Integer;
APIScriptRWU.GET_RESPONSE_JSON(AllPagesBodyList);
for i := 1 to AllPagesBodyList.Count do begin
JSONBody := AllPagesBodyList.Get(i);
// ... process the JSON body of current page
end;