How to deal with a list of orders and “divide by order” and pay the order number for each order?

Hello,
I’m new and I’m getting familiar with the tool.

I have this problem, I’m not sure how to go through all my ERP orders and get the “order number” for each order and move the “order number” variable to a URL as an expression for the http request to change the “order number” URL in each iteration.



Example of my data entry

Yeah, if you want n8n to iterate over all orders you gotta format the data to something n8n understands. The example below should do it. The important part here is the function node that takes the ‘pedidos’ from the first HTTP request and map them to the structure n8n uses.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://mockup-pj5l0yxsjrbr.runkit.sh/",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = [];\n\nconst data = items[0].json.pedidos;\n\nfor (const item of data) {\n  \n   results.push({\n     json: item\n   })\n}\n\nreturn results;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "url": "=https://testingn8n-85cmorealoiy.runkit.sh?pedido={{$node[\"Function\"].json[\"pedido\"][\"numero\"]}}",
        "options": {}
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1020,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

@RicardoE105 wow it worked now, i would never imagine such a simple solution.

I just have one more question inside the loop, will it go through all the other orders and dynamically change the “order code”?

Thank you very much!

Happy it worked. Yes, It will automatically literate over the orders calling the second HTTP Request with each order id.

1 Like

Thank you again @RicardoE105 :smiley: :+1: :v: