Loop HTTP Request Results

New to N8N, but loving it so far! I am making an HTTP request for customers, when I make the request I am passing in the phone number for the customer (removed for privacy), I am getting 1 item returned with a JSON body that includes multiple profiles for the individual customer.

I need to grab the ProfileID from each of the returned customer accounts, then loop a new HTTP Post request using only the ProfileID for each of the individual ProfileID(s).
Essentially updating information on each of the accounts that the customer may have. Profile count changes on past customer events. Some customers have 2, others can have 12. In my new POST request, I am only using the ProfileID from each of the return customer accounts.

Thank you for your help!

Get Accounts > Loop based on previous response > Post Update each customer accounts using only the ProfileID(s) returned from the GET request.

Current nodes, based on some reading I am guessing I will need a function or loop node in between?
HTTP GET - List of customer accounts.
HTTP POST - Update each customer profile, using the profile id.

Output from HTTP Get Node -

[
  [
    {
      "PROFILEID": 12345678,
      "FIRSTNAME": "James",
      "LASTNAME": "Smith ",
      "GENDER": "F",
      "EMAIL": "[email protected]",
    },
    {
      "PROFILEID": 87654321,
      "FIRSTNAME": "Jane",
      "LASTNAME": "Smith ",
      "GENDER": "F",
      "EMAIL": "[email protected]",
    }
  ]
]

Hi @reb3l12

Welcome to the community!

N8n loops through the items that exist in the workflow.
At a first glance it will simply be one get and then a post to update the records. Of course you need a set or something in between to add / change the fields you want.

It is possible you need to split the array into items. You should be able to see how many items exist. This would tell you if you still need to split them or not.

Hope this helps.
If it does not, please share your workflow and the exact output of the Get and needed input for the Post. Then we can help you further if needed.

Thank you for the warm welcome!

That make’s sense, I think you are correct that the items would need to be split since N8N only shows 1 item returned (however multiple customers in the response). Actually above is the exact output of the Get and what I need for the input Post would essentially be a list of the ProfileIDs, in the case above it’s two but would need to flex based on how many are retrieved. Then I would loop thru the list.

Let me know if this makes sense. If not, I can clean up the workflow for client privacy and redaction.

Cheers,

It’s not completely clear to me what the post is going to look like.
Can you give an example?

fyi for one piece of the puzzle. Activate “Options → Split Into Items” on the HTTP Request node. It will then automatically split the data into different items if an array gets returned.

1 Like

Interesting! I’ll try that as well. If the items are split, how would you loop them or does N8N trigger the POST request for each item natively?

Ok. I’ll clean up and share when I get back.