Handling OData API Pagination with Domain Switching

Hello everyone,

I’m new to Make.com and I need your help.

I have an issue with my application. I want to retrieve all data from my API and fill a Google Sheet table. However, the response from my request looks like this:

{
“d”: {
“results”: [
{
“__metadata”: {
“uri”: “http://localhost:8091/odata_apisf/LS_Country(‘AC’)”,
“type”: “LeadSuccessAPISFOData.LS_Country”
},
“Id”: “AC”,
“LGNTINITLandViewId”: 247,
“Country”: “Country A”
}
],
“__next”: “http://localhost:8091/odata_apisf/LS_Country?$skiptoken=‘ID’&$format=json
}
}

The problem is that my API uses pagination with a __next field that contains the URL of the next page. But this URL is generated with the development domain (localhost) whereas in production I need to use a different domain (lstest.convey.de).

I forgot to mention that the first call gives me just the first 100 records and the second call with the URL: http://lstest.convey.de/apisftest/LS_Country?skiptoken=‘SL’& format=json would allow me to get the next ones.

I don’t know who can really help me implement this pagination logic. I want to retrieve all the data when running the scenario. Thanks for your help.

After several attempts, I found a solution using a JavaScript module with this function to correctly rebuild the URL:

javascript

function getNextUrl(next, serverName, apiName) {
  let url = "";
  if (next && typeof next === "string") {
    const viewNamePos = next.lastIndexOf("/");
    if (viewNamePos >= 0) {
      url = `https://${serverName}/${apiName}${next.substring(viewNamePos)}`;
    }
  }
  return url;
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.