Looping Httprequest for each item in Array

Hi Team,
Thanks for such wonderful tool.

Here is my use case. i will be receiving array of item from webhook response, then i want to make a http request for each item in the array and need to consolidate the response of all http request into single response object. Kindly confirm is it possible with n8n available nodes?

Great to hear that you enjoy n8n!

Here an example workflow:

1 Like

Thanks for the reply.

How to set timeout to each loop? and how to continue looping if code is not 2XX?
I was checking response code for 140+ urls to find out 404 websites. But continually got
“Error: unable to verify the first certificate”

here is my workflow

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        280,
        270
      ]
    },
    {
      "parameters": {
        "url": "http://www.samacn.org.cn/",
        "responseFormat": "string",
        "options": {
          "fullResponse": false
        },
        "headerParametersUi": {
          "parameter": []
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        480,
        290
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "data",
              "cssSelector": "div .nlist ul li",
              "returnValue": "html",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        670,
        290
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "url",
              "cssSelector": "a",
              "returnValue": "attribute",
              "attribute": "href"
            },
            {
              "key": "name",
              "cssSelector": "a"
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract1",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        860,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\n\n// Loop over inputs and add a new field called 'myNewField' to the JSON of each one\nnewItems = []\nfor (item of items) {\n  console.log(item['json']['name'])\n  console.log(item['json']['url'])\n  console.log('name+url')\n  if ((item['json']['name'] && item['json']['url']) === '') continue;\n  newItems.push(item)\n}\n\n// You can write logs to the browser console\nconsole.log('Done!');\n\nreturn newItems;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1040,
        290
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"Function\"].json[\"url\"]}}",
        "responseFormat": "string",
        "options": {
          "ignoreResponseCode": true
        },
        "headerParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1210,
        270
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract": {
      "main": [
        [
          {
            "node": "HTML Extract1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract1": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey @liqt91!

Welcome to the community :sparkling_heart:

You can refer to these post to learn how to add a timeout:

To continue the workflow and ignore the errors you can set the Continue on Fail option to true. In the node, go to the Settings tab and toggle the option to true.

1 Like