Extend input items with data from http call

Describe the problem/error/question

I have to following case I want to solve.
I get a list of users via an HTTP-Call. As output I get 100 items with user data.
Now I need to make another HTTP-Call to get all the groups for my users.
For the second call I need the user id from every user from the first call and for every user get the assigned groups.

I can make this work, but after the second HTTP-Call I get all groups as a big list.
What I need would be the list of my users and for eery user the groups merged into the user object.

Like so:
My users items after the first call:

[
  { userId: 1},
  { userId: 2},
  { userId: 3}
]

Get groups for a user returns:

[
  {groupId: 1},
  {groupId: 2}
]

What I need in the end:

[
  { userId: 1, groups: [
    {groupId: 1},
    {groupId: 2}
  ]},
  { userId 2, groups: []},
  { userId: 3, groups: [
    {groupId: 2},
    {groupId: 4}
  ]}
]

I don’t get how I can achieve that. What I have right now is:

I have 100 users and the second call gets all the groups. But I then get a huge list of 1386 groups which are all groups from all users. But I need them combined with the users so I get 100 items (all users) with their groups. How can I do that?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @Zwergal

The easiest way is to use the Loop node

1 Like

@barn4k Thanks for the hint.
I was able to adapt this to my workflow and now it is working for me!
I already found the loop node but I didn’t understand how it works.
With your example and the use of the aggregate/edit fieds node it is now clear how to achieve my use case.

Thank you very much again!

1 Like

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