Struggling with Looping HTTP Requests and Looping Through All Items (Hubspot API)

Describe the problem/error/question

Hi all, I’m trying to build an n8n workflow that:

  • Calls the HubSpot API to retrieve all companies that match a filter (e.g. those missing a specific property).

  • For each company, it searches for contacts and applies logic to assign a best fit.

  • Handles pagination of the API properly, and makes sure every company item is processed once through the loop.

Current Setup (High-level):

  1. Initial HTTP Request (HubSpot search) using a JSON body (not query params).

  2. Loop or recursive structure to paginate through the full list of companies (limit: 100 per page, using after for pagination).

  3. Flatten JSON / Code node to spread the company list.

  4. Loop node to process each company individually (find contacts → assign best → update Hubspot)

  5. At the end of the loop, I either:

    • Try to detect if there’s a next after cursor and re-trigger the same flow,

    • Or, use HTTP Request’s built-in pagination tab (which I just tried).

Issues I’ve Faced (Timeline-style):

  • Attempt 1: Flattened all company results and fed into loop. But loop only ran 13 times (same number as HTTP calls), ignoring the full item count (e.g. 1200+).

  • Attempt 2: Tried wiring up a manual recursive loop that re-triggers with the next after cursor from the previous page. It ended up causing infinite loops or incorrect behavior—like workflows looping before all prior items were done.

  • Attempt 3: Tried using HTTP Request V3’s Pagination feature. But this seems to require the after cursor to be passed as a query param. Since HubSpot expects the cursor in the JSON body, I kept getting errors like JSON parameter needs to be valid JSON.

  • Other failed attempts: Tried injecting the after dynamically into the request body via {{ $response.body.paging.next.after }} inside the JSON editor—this fails validation and breaks at runtime.

What I Need Help With

  • Is there a clean way to paginate through HubSpot’s API when the after cursor needs to be passed in the JSON body?

  • Should I abandon the HTTP Pagination feature and handle this manually with code or a loop?

  • What’s the best way to avoid processing items prematurely before pagination is complete?

  • How do I ensure that all items are flattened and passed through the loop before triggering the next pagination cycle?

Would love a sanity check or examples if anyone’s tackled something similar. Thank you :folded_hands:

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