HTTP node that run on a list

Describe the problem/error/question

I have an HTTP node that returns an array of objects like this:


"height": 
188,
"url": 
"https://i.ytimg.com/vi/Oa_RSwwpPaA/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCEPP94ZLzpFMkNipcHS_A11u5g2g",
"width": 
336
}
],
"title": 
"Benson Boone - Beautiful Things (Official Music Video)",
"videoId": 
"Oa_RSwwpPaA"
}
},

Then, I have another HTTP node that should be executed for every item and take the videoId value from it.

How can I make the second node to be executed for each item and get the video id?
I can’t find a documentation resource for this.

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:

@n8n

  • n8n version:
    last version>

  • Database (default: SQLite):
    I didn’t link a database.

  • n8n EXECUTIONS_PROCESS setting (default: own, main):
    I don’t know what is this!

  • Running n8n via (Docker, npm, n8n cloud, desktop app):
    I use it on my machine and I run it using the command prompt by installing node.js and npm and starting it via tunnel

  • Operating system:
    Windows 10

I thought this was irrelevant information!

Welcome to the community @Salem_Mo !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


I believe you need to segregate the items with Split Out node. As you did not provide the full input (your sample of JSON is actually broken) I’m not sure how that looks like to be sure.

If I understood you right, the array of objects looks something like this

{
  "array_of_objects": [
    {
      "height": 188,
      "url": "https://i.ytimg.com・..",
      "width": 336,
      "title": "Title 1",
      "videoId": "Oa_RSwwpPaA"
    },
    {
      "height": 188,
      "url": "https://i.ytimg.com・...",
      "width": 336,
      "title": "Title 1",
      "videoId": "qe_Rabcbcc"
    }
  ]
}

Then you can split it as below.

Thank you @ihortom and I am sorry for the broken JSON.

This is the right JSON:

{
  "contents": [
    {
      "index": 1,
      "type": "video",
      "video": {
        "author": {
          "canonicalBaseUrl": "/channel/UCNL1ZadSjHpjm4q9j2sVtOA",
          "channelId": "UCNL1ZadSjHpjm4q9j2sVtOA",
          "title": "Lady Gaga"
        },
        "isLiveNow": false,
        "lengthSeconds": 253,
        "thumbnails": [
          {
            "height": 94,
            "url": "https://i.ytimg.com/vi/kPa7bsKwL-c/hqdefault.jpg?sqp=-oaymwEbCKgBEF5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLD_P-QKwzQUAf6bJlsC6-L2wJn-Sw",
            "width": 168
          },
          {
            "height": 110,
            "url": "https://i.ytimg.com/vi/kPa7bsKwL-c/hqdefault.jpg?sqp=-oaymwEbCMQBEG5IVfKriqkDDggBFQAAiEIYAXABwAEG&rs=AOn4CLByaN7md6ZmoEzuumhHAKvci04EfQ",
            "width": 196
          },
          {
            "height": 138,
            "url": "https://i.ytimg.com/vi/kPa7bsKwL-c/hqdefault.jpg?sqp=-oaymwEcCPYBEIoBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLCH5uDEIZu_jXSckPyCcwxvc_FDDQ",
            "width": 246
          },
          {
            "height": 188,
            "url": "https://i.ytimg.com/vi/kPa7bsKwL-c/hqdefault.jpg?sqp=-oaymwEcCNACELwBSFXyq4qpAw4IARUAAIhCGAFwAcABBg==&rs=AOn4CLAQiJs48T0874m4PwpyLlb_MVZ0zg",
            "width": 336
          }
        ],
        "title": "Lady Gaga, Bruno Mars - Die With A Smile (Official Music Video)",
        "videoId": "kPa7bsKwL-c"
      }
    },
other objects in the "contents" array ...
  ]
}

This is the response of the first HTTP node. I want the second HTTP node executed for each item in the “contents” array.
The second HTTP request should take the value of the “videoId” of each item in the “contents” array and use it as a query parameter, so I need to reference this “videoId” in the second HTTP node in a way that makes it run for each item.

I guess you mean that I have to add a Split Out node between my first HTTP node (that returns an object containing an array) and my second HTTP node (that should be executed for each item in the array), I can do it but still can’t recognize how to reference the “videoId” key of the array items of the first node in the query parameter field of the second node?

I am sorry for the incomplete information in my main topic

Exactly right. The Split Out node would have to be split on the property contents. Than videoId could be referenced in the 2nd HTTP Request node with the expression {{ $json.video.videoId }}.

2 Likes

Ok, I guess that n8n will handel excuting the second node for each item, but I used a Loop node beacuse I found that I need to add a pause before the second node because I only can call the endpoint once per second, and it works now, thank you for helping.

1 Like

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