Help With Pagination | With SAP

Hello, I am trying to retrieve an unknown list of items (values[0]) from SAP using a GET request, after performing a LOGIN beforehand.

The response is limited to 20 values. At the end of the JSON, I see the following:

odata.nextLink
Items?$filter=Properties34%20eq%20%27tYES%27&$skip=20

I understand that the response is limited to 20 items and that this limit is not configurable. I would like to be able to paginate the results in batches of 20 (using a loop if necessary, although that is not my preferred approach).

After the HTTP Request node, I have JavaScript code to filter and process some specific fields from each Value[], and finally convert the result into an XLSX file and upload it to an SFTP server.

The issue is that it only returns 20 Value[]. Everything else works correctly.

1 Like

Hey @ArielGonzales Welcome to the n8n community!

You’re very close! The missing piece is configuring the HTTP Request node’s pagination to follow odata.nextLink, and then adjusting your Code node to process the complete paginated output.

1. Set Up Pagination on the HTTP Request Node

Your SAP OData response includes:

{
  "value": [ /* 20 items */ ],
  "odata.nextLink": "Items?$filter=Properties34%20eq%20%27tYES%27&$skip=20"
}

How to configure:

  • In your HTTP Request node, go to Options > Pagination.
  • Set Pagination Mode to Response Contains Next URL.
  • In Next URL (expression), insert:
{{ 
  $response.body['odata.nextLink'] 
    ? 'https://10.80.13.139:50000/b1s/v1/' + $response.body['odata.nextLink'] 
    : null 
}}

This instructs n8n to keep following the URLs provided in odata.nextLink until it’s null.

  • Set Complete Pagination When to:
{{ !$response.body['odata.nextLink'] }}

This tells n8n when to stop paginating (when odata.nextLink is missing or null).

  • You can leave Max Requests high or empty to fetch all pages.

Result:
n8n will automatically fetch all pages, concatenating all items into a single output.

2. Adjust Your Code Node for the Combined Output

Previously, your code assumed a single response with a value array:

const data = $input.first().json.value;

Now, with pagination, each item in $input represents one item from the combined list, not a page.

Update your code to process all input items:

const items = $input.all();

return items.map(item => {
  const raw = item.json;
  const rawStock = Number(raw.QuantityOnStock || 0);
  const stock = rawStock > 199 ? 199 : rawStock;

  let status;
  if (raw.Valid === 'tNO') {
    status = 'discontinued';
  } else if (raw.Frozen === 'tYES') {
    status = 'out-of-stock';
  } else if (rawStock > 0) {
    status = 'in-stock';
  } else {
    status = 'out-of-stock';
  }

  return {
    json: {
      sku: raw.ItemCode,
      upc: '',
      ean: raw.BarCode || '',
      quantity_available: Math.trunc(stock),
      cost: Number(Number(raw.ItemPrices[11].Price || 0).toFixed(2)),
      status,
      warehouse_code_1: 'ARTERO',
      warehouse_quantity_1: Math.trunc(stock),
    },
  };
});

This way, your code processes all items seamlessly.

3. No Need for Manual Looping

Since the HTTP node handles pagination internally, you don’t need an extra Loop node or manual iteration. It will output all items combined, ready for the next steps.

If you follow these steps, your workflow should correctly handle all paginated data! Let me know if this helps, i have faced the same issue where the error was in my javascript

2 Likes

Thank you so much!!! U Save me!

1 Like

Glad it helped you! Happy n8n-ing :smile:

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