Retrieving Hubspot deals and line items

Describe the problem/error/question

We are using n8n to output Hubspot deals with associated line items. We get a list of deals that fit the range than output the deal to google sheets. After this we get the line items associated with the deal and loop through those adding each one to the sheet.

What is the error message (if any)?

The issue is when a deal has more than 1 line item we use a split in batches after the itemslist node to loop through the line items associated with the deal. If I ran the workflow with the last IF connected to the main loop (first splitinbatches node) it works, as soon as I connect the last IF back to the main loop the data makes it to the sheet but not ordered correctly. Eg. Deal 123456 with 3 line items will only have 1 line item and the other line items are listed under the next deal. Is this approach wrong? It seems like this should work but can’t understand why it doesn’t.

Please share your workflow

Information on your n8n setup

  • n8n version: 0.195.5
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux - not sure what distro

Hi @tonybelonie, I’d suggest you separate the logic into two workflows here to simplify things. Have one workflow fetching your deals, then split the deals up in batches of 1 like you already do.

Then call a sub-workflow (using the Execute Workflow node) for a single deal only. In your sub-workflow you can then be certain that all line items belong to a single deal.

If you update your n8n instance you can then use expressions such as {{ $("<node-name>").first().json.properties.hs_object_id"] }} in your sub-workflow (documented here) to always read the first (and correct) deal ID :slight_smile:

Thanks @MutedJam for the suggested solution. For anyone that finds themself on this thread later. The solution I came to was to actually retrieve the line item in batch from the Hubspot API.

2 Likes

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