{
  "name": "Recipe 2 · the whole table",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "table",
        "responseMode": "responseNode",
        "options": {
          "allowedOrigins": "*"
        }
      },
      "name": "Kitchen bell (Webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        120
      ],
      "webhookId": "vibesprint-table"
    },
    {
      "parameters": {
        "jsCode": "// The table sends a list called \"orders\". Hand every slip on separately.\n// Everything after this box runs once per slip. That is the loop.\nreturn $input.first().json.body.orders.map(o => ({ json: o }));"
      },
      "name": "Split list (Code)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        240,
        120
      ]
    },
    {
      "parameters": {
        "url": "=https://www.themealdb.com/api/json/v1/1/search.php?s={{ $json.dish }}",
        "options": {}
      },
      "name": "Ask the supplier (HTTP Request)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        120
      ],
      "notes": "TheMealDB needs no key. Swap this address for any other supplier."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.meals }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "name": "Recipe found? (IF)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        720,
        120
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a0",
              "name": "dish",
              "value": "={{ $('Split list (Code)').item.json.dish }}",
              "type": "string"
            },
            {
              "id": "a1",
              "name": "qty",
              "value": "={{ $('Split list (Code)').item.json.qty }}",
              "type": "number"
            },
            {
              "id": "a2",
              "name": "status",
              "value": "on the menu",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "recipe",
              "value": "={{ $json.meals[0].strMeal }}",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "kitchen",
              "value": "={{ $json.meals[0].strArea }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "On the menu (Edit Fields)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        960,
        0
      ],
      "notes": "$('Split list (Code)').item reaches back to the slip that belongs to this supplier answer."
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a0",
              "name": "dish",
              "value": "={{ $('Split list (Code)').item.json.dish }}",
              "type": "string"
            },
            {
              "id": "a1",
              "name": "qty",
              "value": "={{ $('Split list (Code)').item.json.qty }}",
              "type": "number"
            },
            {
              "id": "a2",
              "name": "status",
              "value": "not on the menu, ask the chef",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "Ask the chef (Edit Fields)",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        960,
        240
      ]
    },
    {
      "parameters": {
        "numberInputs": 2
      },
      "name": "Back together (Merge)",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1200,
        120
      ]
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "dishes",
        "options": {}
      },
      "name": "One list again (Aggregate)",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1440,
        120
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"table\": $('Kitchen bell (Webhook)').first().json.body.table, \"dishes\": $json.dishes, \"total_dishes\": $json.dishes.map(d => d.qty).reduce((a, b) => a + b, 0) } }}",
        "options": {}
      },
      "name": "Hand it back (Respond)",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1680,
        120
      ]
    }
  ],
  "connections": {
    "Kitchen bell (Webhook)": {
      "main": [
        [
          {
            "node": "Split list (Code)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split list (Code)": {
      "main": [
        [
          {
            "node": "Ask the supplier (HTTP Request)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask the supplier (HTTP Request)": {
      "main": [
        [
          {
            "node": "Recipe found? (IF)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recipe found? (IF)": {
      "main": [
        [
          {
            "node": "On the menu (Edit Fields)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ask the chef (Edit Fields)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On the menu (Edit Fields)": {
      "main": [
        [
          {
            "node": "Back together (Merge)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask the chef (Edit Fields)": {
      "main": [
        [
          {
            "node": "Back together (Merge)",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Back together (Merge)": {
      "main": [
        [
          {
            "node": "One list again (Aggregate)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One list again (Aggregate)": {
      "main": [
        [
          {
            "node": "Hand it back (Respond)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}