{
  "name": "Fetch hierarchical data records from Airtable with multi-level relationships",
  "nodes": [
    {
      "id": "1305d4ee-3227-4adf-99a1-307da4fdef53",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        1340,
        320
      ]
    },
    {
      "id": "300a89e6-ff90-4076-8d93-6189c7669829",
      "name": "Inputs",
      "type": "n8n-nodes-base.set",
      "position": [
        1560,
        320
      ]
    },
    {
      "id": "f1cdb90e-2cc2-4c0a-a9ee-c1bc5feb240f",
      "name": "Split Out Fields",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2440,
        220
      ]
    },
    {
      "id": "894b24e6-3090-46fe-8902-9939595849cd",
      "name": "Add Inverse LinkTo Field name",
      "type": "n8n-nodes-base.set",
      "position": [
        2880,
        220
      ]
    },
    {
      "id": "44e1d4f9-cd50-4e68-be4c-dd62d5e5eeaa",
      "name": "Add origin LinkTo",
      "type": "n8n-nodes-base.set",
      "position": [
        4500,
        680
      ]
    },
    {
      "id": "08f499f3-c675-4e4e-865c-397f705a35dd",
      "name": "Filter Link To fields",
      "type": "n8n-nodes-base.filter",
      "position": [
        2660,
        220
      ]
    },
    {
      "id": "32cbf163-3114-4fb5-983d-de25f53598af",
      "name": "Airtable Schema",
      "type": "n8n-nodes-base.airtable",
      "position": [
        2000,
        220
      ]
    },
    {
      "id": "6d1186d2-96c6-4303-9614-38fa8200a540",
      "name": "Airtable - Get Target Record",
      "type": "n8n-nodes-base.airtable",
      "position": [
        1780,
        220
      ]
    },
    {
      "id": "9211e559-f6b3-4086-8a64-37e2218fa221",
      "name": "Insert linked records to originRecord & Clean Field Name",
      "type": "n8n-nodes-base.code",
      "position": [
        4740,
        680
      ]
    },
    {
      "id": "d928dee8-d050-4ad3-8e54-0dd058900f83",
      "name": "Filter Main Table",
      "type": "n8n-nodes-base.filter",
      "position": [
        2220,
        220
      ]
    },
    {
      "id": "75eb8440-d179-444b-beb1-0e4c41a05293",
      "name": "Get Linked records without Link To fields Except for Level 3",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3100,
        220
      ]
    },
    {
      "id": "6d908b82-5c3d-4e1c-9c9f-547828c7f462",
      "name": "If Has Level 3",
      "type": "n8n-nodes-base.if",
      "position": [
        3540,
        -20
      ]
    },
    {
      "id": "238b89f0-b68d-4e81-a837-0175348281cc",
      "name": "Get L3 Linked records without reverse Link To fields",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        5140,
        -120
      ]
    },
    {
      "id": "b71ff770-0253-4b93-b57b-9ed5a7eb6462",
      "name": "Level 2 records",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        4040,
        60
      ]
    },
    {
      "id": "4d3ad059-ea71-4e76-8ce1-89928b824613",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        4260,
        -40
      ]
    },
    {
      "id": "5e8becd7-9056-424c-bc5c-3cb553b88e78",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        4280,
        680
      ]
    },
    {
      "id": "eee4b3a4-dd73-485c-adbc-db64bb22157f",
      "name": "Repeat L3 links of current L2 table",
      "type": "n8n-nodes-base.set",
      "position": [
        4040,
        -140
      ]
    },
    {
      "id": "8fc621bc-5f9d-4d9c-8c88-12cd7aafca68",
      "name": "Aggregate1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        5580,
        -120
      ]
    },
    {
      "id": "c9d8fabd-b9c1-409a-a899-0dc6260a8199",
      "name": "Split Out L3 Potential Links",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        4700,
        -120
      ]
    },
    {
      "id": "eb8e8c3b-972a-4d6f-878d-cb5d435e0250",
      "name": "Prepare HTTP Call",
      "type": "n8n-nodes-base.set",
      "position": [
        4920,
        -120
      ]
    },
    {
      "id": "25d3c6b3-9f3f-4703-9def-ca7435608d10",
      "name": "Preparing aggregation",
      "type": "n8n-nodes-base.set",
      "position": [
        5360,
        -120
      ]
    },
    {
      "id": "47ac8540-6a58-46b5-b690-6beadcbbd52f",
      "name": "Code to single field property",
      "type": "n8n-nodes-base.code",
      "position": [
        5800,
        -120
      ]
    },
    {
      "id": "1e4f7e9d-923e-4b91-a5a4-3c928f5004a5",
      "name": "Merge with original field property",
      "type": "n8n-nodes-base.set",
      "position": [
        6020,
        -40
      ]
    },
    {
      "id": "6e45ff3e-0e31-4658-a718-51a1b580b8ef",
      "name": "Aggregate to record list",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        4640,
        -400
      ]
    },
    {
      "id": "c791981c-d73f-4af5-b64e-27fec10994bc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3480,
        -720
      ],
      "parameters": {
        "width": 2730,
        "height": 1040,
        "content": "## Level 3 children\n\nThis is an iteration on each L2 records array having level 3 children to be fetched"
      }
    },
    {
      "id": "ec5ebe98-56f9-4568-afc7-2b5202d205b4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        180
      ],
      "parameters": {
        "width": 440,
        "height": 380,
        "content": "## Input\n\n```\n[\n  {\n    \"base_id\": \"appN8nPMGoLNuzUbY\",\n    \"table_id\": \"tblLVOwpYIe0fGQ52\",\n    \"record_id\": \"reczMh1Pp5l94HdYf\",\n    \"level_3\": [\n      \"fldRaFra1rLta66cD\",\n      \"fld3FxCaYk8AVaEHt\""
      }
    },
    {
      "id": "4d689138-a84e-45e2-9202-757057f6a326",
      "name": "Rich Text Fields list",
      "type": "n8n-nodes-base.set",
      "position": [
        5200,
        480
      ]
    },
    {
      "id": "32bfa99d-8675-4bfa-9644-4f0eb10d66a2",
      "name": "Markdown to Html",
      "type": "n8n-nodes-base.code",
      "position": [
        5460,
        480
      ]
    },
    {
      "id": "737044e7-1263-4ef0-a6b3-2746f4532171",
      "name": "If markdown to html",
      "type": "n8n-nodes-base.if",
      "position": [
        4960,
        680
      ]
    },
    {
      "id": "82d7b6f5-a1be-45f1-97b3-0221c5b6263d",
      "name": "Merge2",
      "type": "n8n-nodes-base.merge",
      "position": [
        5860,
        800
      ]
    },
    {
      "id": "57f90bea-9a0b-4093-83ba-1bd18200b84c",
      "name": "Get Airtable Comments",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1880,
        820
      ]
    },
    {
      "id": "ae6b84ef-940e-497a-8081-a1da8ed7f960",
      "name": "Rename comments",
      "type": "n8n-nodes-base.set",
      "position": [
        2100,
        820
      ]
    },
    {
      "id": "d4d73be8-4d60-47b1-be08-057dc4ae0e98",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        -1340
      ],
      "parameters": {
        "width": 920,
        "height": 1500,
        "content": "# Airtable Hierarchical Record Fetcher\n\n## Description\n\nThis n8n workflow retrieves an Airtable record along with its related child records in a hierarchical structure. It can fetch up to 3 levels of "
      }
    },
    {
      "id": "64dd6a5e-20ec-44a3-87d0-aac91b5cd42a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5060,
        360
      ],
      "parameters": {
        "width": 700,
        "height": 280,
        "content": "## Converts Airtable Rich Text (pseudo-markdown) to HTML\n \n**This requires `marked` npm package.** \n\nYou can delete these nodes if you don't need the feature"
      }
    },
    {
      "id": "632211fc-312c-4023-b96f-8b2e1eff561e",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2420,
        -120
      ],
      "parameters": {
        "width": 860,
        "height": 520,
        "content": "## Level 2 children\n\nFor each `Link to another record` fields:\n\n- We fetch the linked records array (up to 100 children) thanks to a `filterbyformula` API trick\n- In those level 2 children records, we"
      }
    },
    {
      "id": "fa4bcdc8-c977-4f4a-89e9-545a97855a38",
      "name": "Loop Over L2 records arrays having L3 children to fetch",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        3820,
        -40
      ]
    },
    {
      "id": "f9589f05-4ec5-4060-a5d6-8a4263be8c0b",
      "name": "Loop Over L2 Records for a given L1 field",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        4480,
        -40
      ]
    },
    {
      "id": "d62be593-40bf-4ba2-83ec-e32121a35d18",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4380,
        -540
      ],
      "parameters": {
        "width": 1820,
        "height": 740,
        "content": "## Level 3 children\n\nThis is an iteration on each record within a record array to fetch its level 3 children"
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Loop Over L2 Records for a given L1 field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inputs": {
      "main": [
        [
          {
            "node": "Airtable - Get Target Record",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Airtable Comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Add origin LinkTo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Code to single field property",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Has Level 3": {
      "main": [
        [
          {
            "node": "Loop Over L2 records arrays having L3 children to fetch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable Schema": {
      "main": [
        [
          {
            "node": "Filter Main Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Level 2 records": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Rename comments": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Markdown to Html": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Fields": {
      "main": [
        [
          {
            "node": "Filter Link To fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add origin LinkTo": {
      "main": [
        [
          {
            "node": "Insert linked records to originRecord & Clean Field Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Main Table": {
      "main": [
        [
          {
            "node": "Split Out Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare HTTP Call": {
      "main": [
        [
          {
            "node": "Get L3 Linked records without reverse Link To fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If markdown to html": {
      "main": [
        [
          {
            "node": "Rich Text Fields list",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Filter Link To fields": {
      "main": [
        [
          {
            "node": "Add Inverse LinkTo Field name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Airtable Comments": {
      "main": [
        [
          {
            "node": "Rename comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Preparing aggregation": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Rich Text Fields list": {
      "main": [
        [
          {
            "node": "Markdown to Html",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate to record list": {
      "main": [
        [
          {
            "node": "Loop Over L2 records arrays having L3 children to fetch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable - Get Target Record": {
      "main": [
        [
          {
            "node": "Airtable Schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out L3 Potential Links": {
      "main": [
        [
          {
            "node": "Prepare HTTP Call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Inverse LinkTo Field name": {
      "main": [
        [
          {
            "node": "Get Linked records without Link To fields Except for Level 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code to single field property": {
      "main": [
        [
          {
            "node": "Merge with original field property",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge with original field property": {
      "main": [
        [
          {
            "node": "Loop Over L2 Records for a given L1 field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Repeat L3 links of current L2 table": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over L2 Records for a given L1 field": {
      "main": [
        [
          {
            "node": "Aggregate to record list",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Split Out L3 Potential Links",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get L3 Linked records without reverse Link To fields": {
      "main": [
        [
          {
            "node": "Preparing aggregation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over L2 records arrays having L3 children to fetch": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Repeat L3 links of current L2 table",
            "type": "main",
            "index": 0
          },
          {
            "node": "Level 2 records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert linked records to originRecord & Clean Field Name": {
      "main": [
        [
          {
            "node": "If markdown to html",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Linked records without Link To fields Except for Level 3": {
      "main": [
        [
          {
            "node": "If Has Level 3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}