When pulling live data from REST APIs in Alteryx, you quickly hit a common bottleneck: pagination. You configure the Download tool, hit Run, and celebrate when clean JSON comes back, only to realize the API capped your response at 100 records out of 15,000. You do not know how many pages exist upfront, and you cannot request Page 2 until Page 1 tells you where it lives.

If you read my previous post on Alteryx macros, you already know how to package repeatable logic into a reusable tool. Standard and Batch Macros work well when you know all inputs ahead of time, such as looping through 50 regional Excel files. API pagination is different because each request depends on the previous run's output, making it the textbook use case for an Iterative Macro.

Anatomy of a Paginated API Response

Alongside the records array (data), modern APIs return a pagination object pointing to the next batch:

Page 1 (Loop Continues)
Plain text
{
  "data": [ /* 3 records */ ],
  "pagination": {
    "current_page": 1,
    "has_more": true,
    "next_page_url": "...?page=2"
  }
}
Page 4 (Stop Condition)
Plain text
{
  "data": [ /* final record */ ],
  "pagination": {
    "current_page": 4,
    "has_more": false,
    "next_page_url": null
  }
}

On Page 4, has_more switches to false and next_page_url becomes null, giving us our stop condition.

How the Iterative Loop Works

Iterative macros can feel counterintuitive because data flows backward from an output anchor to an input anchor:

Step-by-Step Build: The Pagination Engine

Step 1: Set Up the Macro Input and Download

  1. Open a new workflow in Alteryx Designer and set the workflow type in Workflow Configuration to Iterative Macro.
  2. Add a Macro Input tool with a Text Input field named URL containing your Page 1 endpoint ([https://api.example.com/v1/orders?page=1](https://api.example.com/v1/orders?page=1)).
  3. Connect a Throttle tool (5 records per second) followed by a Download tool to avoid HTTP 429 rate limits.
  4. In the Download tool's Basic tab, select URL as the Field and output to DownloadData, then attach a JSON Parse tool.

Step 2: Split the Stream

Use two Filter tools branching off JSON Parse to separate records from your loop trigger.

Branch A: The Data Stream

  • Filter: StartsWith([JSON_Name], "data.")
  • Reshape: Connect a RegEx tool to JSON_Name in Parse mode using data\.(\d+)\.(.*) to create Row_ID and Field_Name.
  • Tabularize: Connect a Cross Tab tool. Group by Row_ID, set headers to Field_Name, and aggregate JSON_ValueString using First.
  • Output: Connect a Macro Output tool named Data.

Branch B: The Loop Trigger

  • Filter: [JSON_Name] = "pagination.next_page_url" AND !IsNull([JSON_ValueString])
  • Clean Schema: Use a Select tool to keep only JSON_ValueString and rename it to URL to match your Macro Input.
  • Output: Connect a second Macro Output tool named Loop.

Step 3: Wire the Interface Designer

  1. Open the Interface Designer (Ctrl + Alt + D) and click the Properties gear icon.
  2. Set Iteration Input to your Macro Input and Iteration Output to your Loop output.
  3. Under Output Mode, select Auto Configure by Name (Wait Until All Iterations Run) so optional fields on early pages do not cause schema errors later.
  4. Set Maximum Number of Iterations to 100 to prevent infinite loops, then save as API_Paginator.yxmc.

Adapting to Other Pagination Styles

If your API uses offset or cursor parameters instead of a full URL, add a Formula tool before your Loop output:

  • Offset / Limit: "[https://api.example.com/v1/orders?limit=3&offset=](https://api.example.com/v1/orders?limit=3&offset=)" + ToString(([Engine.IterationNumber] + 1) * 3)
  • Cursor / Token: "[https://api.example.com/v1/orders?cursor=](https://api.example.com/v1/orders?cursor=)" + [JSON_ValueString]

Production Guardrails

  • Catch Silent Failures: If Page 3 hits a 401 or 500 error, JSON Parse will find no next_page_url and stop early with partial data. Add a Filter checking Contains([DownloadHeaders], "200 OK") connected to an error Message tool.
  • Use a Batch Macro When Page Count Is Known: If an API gives you total_pages: 500 on Page 1, use a Generate Rows tool (1 to 500) feeding a Batch Macro instead.

Once saved, drop API_Paginator.yxmc into your main workflow, feed it a single Text Input containing your Page 1 URL, and let it run. Instead of manually stitching together partial exports or writing custom Python scripts, you now have a reusable drag-and-drop tool that pulls complete datasets automatically.