{
  "name": "N8N TO AIRTABLE BACKUP - SMART SYNC",
  "nodes": [
    {
      "parameters": {
        "filters": {},
        "requestOptions": {}
      },
      "id": "3a281199-3810-444b-aab8-46d07f836353",
      "name": "Get all n8n Workflow",
      "type": "n8n-nodes-base.n8n",
      "position": [
        -1232,
        -80
      ],
      "typeVersion": 1,
      "credentials": {
        "n8nApi": {
          "id": "yc0Y1ehXfrL9QnPJ",
          "name": "n8n account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "56428ff0-6e3d-4a64-9f16-c7054abdbb64",
              "leftValue": "={{ $('search').item.json.udpated_at.toDateTime() }}",
              "rightValue": "={{ $('loop_items').item.json.updatedAt.toDateTime() }}",
              "operator": {
                "type": "dateTime",
                "operation": "after"
              }
            },
            {
              "id": "b8541e86-902c-4f1d-afae-ab314ef0492d",
              "leftValue": "={{$json.file !== underfine}}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -112,
        -224
      ],
      "id": "148fa1c4-e554-45e7-a794-65548659d1b0",
      "name": "If"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -1008,
        -80
      ],
      "id": "894f59ef-cd96-4656-874a-8da87c800fb6",
      "name": "loop_items"
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable TableID\"] }}",
          "mode": "id"
        },
        "filterByFormula": "=id_n8n='{{ $('loop_items').item.json.id }}'",
        "returnAll": false,
        "limit": 1,
        "options": {
          "fields": [
            "id_n8n",
            "name",
            "udpated_at",
            "file"
          ]
        }
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        -560,
        -144
      ],
      "id": "b625a6e9-256c-4522-a10f-6aff0e9f2e81",
      "name": "search",
      "alwaysOutputData": true,
      "credentials": {
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "0f808471-448f-4dfe-9c1d-a81758160e44",
              "leftValue": "={{$json.isEmpty()}}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -336,
        -144
      ],
      "id": "837e7b52-c36c-461f-a968-28eee48ee205",
      "name": "If1"
    },
    {
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable TableID\"] }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "name": "={{ $('loop_items').item.json.name }}",
            "id_n8n": "={{ $('loop_items').item.json.id }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "id_n8n",
              "displayName": "id_n8n",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "file",
              "displayName": "file",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "array",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": true
            },
            {
              "id": "udpated_at",
              "displayName": "udpated_at",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        112,
        0
      ],
      "id": "3b7562b7-74d2-4526-98af-e85fb8444fdd",
      "name": "Create a record",
      "credentials": {
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Code Node: Prepare JSON for Airtable Attachment Upload\nconst jsonString = JSON.stringify($json, null, 2);\nconst buffer = Buffer.from(jsonString, 'utf-8');\nconst base64Content = buffer.toString('base64');\nreturn {\n   contentType: \"text/plain\",\n    file: base64Content,\n    filename: `${$json.name || 'workflow'}-${$json.id}.json`\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -784,
        -144
      ],
      "id": "e93b8c8c-f922-4716-b705-d644781eb789",
      "name": "file"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://content.airtable.com/v0/{{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}/{{ $json.id }}/file/uploadAttachment",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "airtableTokenApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $('file').first().json.toJsonString() }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        336,
        -288
      ],
      "id": "7b96205d-323d-43ae-b714-167f93e14d51",
      "name": "Upload file",
      "credentials": {
        "airtableApi": {
          "id": "fHjTWkcjYUXnJHxk",
          "name": "Airtable account"
        },
        "httpBearerAuth": {
          "id": "IOabnji0oayI79nv",
          "name": "Airtable Bearer Auth"
        },
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    },
    {
      "parameters": {
        "amount": 2
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        560,
        -144
      ],
      "id": "8e5e42c6-edfa-426c-944f-584dbb05c989",
      "name": "Wait",
      "webhookId": "52dea046-f1e9-4c9c-b402-0a8baf2cb5d8"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 4
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -1680,
        128
      ],
      "id": "12790d7a-b045-4cca-a9e6-76505512d79f",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "37c2107f-ae3a-492b-aa43-68df0bd666db",
              "name": "Airtable BaseID",
              "value": "appKFrFoqiDhgEY4D",
              "type": "string"
            },
            {
              "id": "a1c583a7-30e7-4505-89d7-e5e816b1ff20",
              "name": "Airtable TableID",
              "value": "tblXjQtcl4EMDKWKu",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1456,
        128
      ],
      "id": "3fe88b7c-5b85-40ec-a626-34de1b09fd40",
      "name": "Airtable Info"
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable TableID\"] }}",
          "mode": "id"
        },
        "options": {
          "fields": [
            "id_n8n",
            "name"
          ]
        }
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        -1232,
        416
      ],
      "id": "fe01ea9a-485b-4791-8fa1-5275f718bc92",
      "name": "Search records",
      "credentials": {
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "workflowId": {
          "__rl": true,
          "value": "={{ $json.id_n8n }}",
          "mode": "id"
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.n8n",
      "typeVersion": 1,
      "position": [
        -784,
        336
      ],
      "id": "1ed320ac-beb8-41bb-8f3d-003934756d89",
      "name": "Get a workflow",
      "alwaysOutputData": true,
      "credentials": {
        "n8nApi": {
          "id": "yc0Y1ehXfrL9QnPJ",
          "name": "n8n account"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -1008,
        416
      ],
      "id": "aa8613f3-3b77-418a-af48-190161fd4e4d",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "operation": "deleteRecord",
        "base": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable TableID\"] }}",
          "mode": "id"
        },
        "id": "={{ $('Loop Over Items').item.json.id }}"
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        -560,
        416
      ],
      "id": "cca298a7-62df-4dff-afaa-bb1eb32bcc6a",
      "name": "Delete a record",
      "credentials": {
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    },
    {
      "parameters": {
        "amount": 2
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -336,
        416
      ],
      "id": "23223d2b-8171-44a8-ac7d-2d4dcf1777c0",
      "name": "Wait1",
      "webhookId": "52dea046-f1e9-4c9c-b402-0a8baf2cb5d8"
    },
    {
      "parameters": {
        "content": "\n\nBRANCH 1 (TOP): INTELLIGENT BACKUP\n• Get all workflows from n8n → Loop each workflow\n• Check 3 scenarios:\n  1️⃣ FIRST BACKUP: Not in Airtable → Create record + Upload file\n  2️⃣ HAS UPDATE: updatedAt(n8n) > updatedAt(Airtable) → Update + Re-upload\n  3️⃣ FILE DELETED: Record exists but file missing → Re-upload backup\n\nLOGIC FLOW:\n└─ If1: Record exists?\n   ├─ NO → Create new record (first backup)\n   └─ YES → If: Need update? (2 conditions AND)\n              ├─ updatedAt(n8n) > updatedAt(Airtable) ✓\n              ├─ file !== undefined ✓\n              └─ BOTH TRUE → Update record + Upload new file\n              └─ FALSE → Skip (no backup needed)\n\n⏱️ Wait 3s between operations to avoid Airtable rate limit (5 req/s)",
        "height": 624,
        "width": 2176
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        -464
      ],
      "typeVersion": 1,
      "id": "71f635fb-09dd-4454-89fe-152d55e7c984",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "🧹 BRANCH 2 (BOTTOM): CLEANUP DELETED WORKFLOWS\n\nFLOW:\n• Get all records from Airtable\n• Loop each record → Get workflow from n8n (with error handling)\n  \nNODE \"Get a workflow\":\n├─ ✅ SUCCESS → Workflow still exists → Skip\n└─ ❌ ERROR (404) → Workflow deleted → Delete Airtable record\n\nConfig: onError = \"continueErrorOutput\" + alwaysOutputData = true\n→ Error output goes to \"Delete a record\" path\n→ Success output skips deletion\n\n💡 Keeps Airtable synced with n8n by removing orphaned records",
        "height": 304,
        "width": 1680
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        272
      ],
      "typeVersion": 1,
      "id": "cd3a6cc4-de88-432b-8732-ea89a2078c27",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "operation": "update",
        "base": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable BaseID\"] }}",
          "mode": "id"
        },
        "table": {
          "__rl": true,
          "value": "={{ $('Airtable Info').item.json[\"Airtable TableID\"] }}",
          "mode": "id"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "file": "[] ",
            "id": "={{ $json.id }}",
            "name": "={{ $('loop_items').item.json.name }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": false
            },
            {
              "id": "id_n8n",
              "displayName": "id_n8n",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "name",
              "displayName": "name",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "file",
              "displayName": "file",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "array",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": true
            },
            {
              "id": "udpated_at",
              "displayName": "udpated_at",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        112,
        -288
      ],
      "id": "895de3bc-b280-473d-92fd-5e25bcb9dcdc",
      "name": "Empty File",
      "credentials": {
        "airtableTokenApi": {
          "id": "686xRmB0RTZAXKlx",
          "name": "Airtable Personal Access Token account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Get all n8n Workflow": {
      "main": [
        [
          {
            "node": "loop_items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "loop_items": {
      "main": [
        [],
        [
          {
            "node": "file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create a record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a record": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "file": {
      "main": [
        [
          {
            "node": "search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Empty File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "loop_items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Airtable Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable Info": {
      "main": [
        [
          {
            "node": "Search records",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get all n8n Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search records": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Get a workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a workflow": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete a record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a record": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Empty File": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "afb6c659-622b-40c0-9bff-c3b11b4b04ba",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "cf2c59faeb7eede7502cc72a5b6f4e4cab32f5d4531e481c855a962838127e51"
  },
  "id": "4n1eg9qjwl7x9X2G",
  "tags": []
}