{
  "name": "Import workflows and map their credentials using a multi-form",
  "nodes": [
    {
      "id": "eb3d4912-09c3-4c17-8e2b-94dd15e145f4",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2960,
        440
      ]
    },
    {
      "id": "56b7a01f-47a0-4884-9200-5f5f695ab355",
      "name": "Export Credentials",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        3180,
        620
      ]
    },
    {
      "id": "85de1146-4d61-45bf-b225-956d3d16e84b",
      "name": "Get Credentials Data",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        3400,
        620
      ]
    },
    {
      "id": "187f1f50-472f-41ac-96e8-9c2f17fa3c00",
      "name": "Binary to JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3620,
        620
      ]
    },
    {
      "id": "85d79317-786a-49eb-ade4-f9d0949c5bf4",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        4060,
        500
      ]
    },
    {
      "id": "6976901c-a052-47fa-a754-217fd5d0f58e",
      "name": "Collect Credentials to Replace",
      "type": "n8n-nodes-base.merge",
      "position": [
        3040,
        1120
      ]
    },
    {
      "id": "c5b7ab56-c833-4405-913a-1a484094a6ff",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "position": [
        980,
        620
      ]
    },
    {
      "id": "a9287c9a-ddf4-4023-b997-bb7b12e2d0ee",
      "name": "Prepare Request Data",
      "type": "n8n-nodes-base.code",
      "position": [
        1640,
        620
      ]
    },
    {
      "id": "85ccc4bf-a465-49bf-ac17-9933f1b9d46d",
      "name": "Get Workflows",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1860,
        620
      ]
    },
    {
      "id": "2d86c12d-f308-4cdc-96a4-ab4cbecd39ad",
      "name": "No Operation",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3180,
        440
      ]
    },
    {
      "id": "8ef0f34d-2468-450e-8a3c-e3d9ad9e371b",
      "name": "Determine Workflow Source",
      "type": "n8n-nodes-base.if",
      "position": [
        760,
        500
      ]
    },
    {
      "id": "3ff270a7-5837-40b5-85b4-da3b28ae6147",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        520
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "## Setup instances\nEach instnce requires a name, apiKey and baseURL"
      }
    },
    {
      "id": "4d0d4684-5ffc-4e12-8d05-55245339fd96",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        680
      ],
      "parameters": {
        "width": 535.6419634856759,
        "height": 223.19907940161124,
        "content": "## Instances config example\n```\n[\n  {\n    \"name\": \"n8n-test\",\n    \"apiKey\": \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n    \"baseUrl\": \"https://n8n-test.example.com/api/v1\"\n  },\n  {\n    ...\n  }\n]\n```"
      }
    },
    {
      "id": "e76e291e-511b-4612-836f-ae6f7af1d3de",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        400
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "A form which collects the source option.\n*Consider securing the form using Basic Auth.*"
      }
    },
    {
      "id": "38ecbde8-9081-4509-9fa3-c5b2d568ebad",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        700,
        400
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Switch between the available options"
      }
    },
    {
      "id": "efa893aa-fce5-45ff-a234-6e73235a33ea",
      "name": "Error1",
      "type": "n8n-nodes-base.form",
      "position": [
        3700,
        1220
      ]
    },
    {
      "id": "e5edd30e-6396-407a-bd3b-a5e0f66c7e3a",
      "name": "Error",
      "type": "n8n-nodes-base.form",
      "position": [
        2080,
        700
      ]
    },
    {
      "id": "c410045e-4adf-4304-910a-7cd5868892d3",
      "name": "Split Out Workflows",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2080,
        540
      ]
    },
    {
      "id": "5fafa399-0c6b-4db0-9b01-319a02368eee",
      "name": "Get Workflow Names",
      "type": "n8n-nodes-base.code",
      "position": [
        2520,
        540
      ]
    },
    {
      "id": "b7408a47-97ff-45da-b8e7-bb2380f61155",
      "name": "Sort by updatedAt DESC",
      "type": "n8n-nodes-base.sort",
      "position": [
        2300,
        540
      ]
    },
    {
      "id": "74741a71-79b8-4479-9dac-826db7984620",
      "name": "No Operation1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        4280,
        680
      ]
    },
    {
      "id": "89657c6f-a703-4145-b690-7234583bbe7a",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1500,
        1240
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 294.9905826938254,
        "content": "## Map Credentials\nBeing mapped by name since one workflow can have multiple credentials of the same type."
      }
    },
    {
      "id": "a2d21bb5-5118-4ea2-920b-1c05570da610",
      "name": "Rename Keys",
      "type": "n8n-nodes-base.renameKeys",
      "position": [
        3840,
        620
      ]
    },
    {
      "id": "d756edc6-cf0d-4a35-b29c-99e5ec41c4db",
      "name": "Create Workflow",
      "type": "n8n-nodes-base.n8n",
      "position": [
        3480,
        1120
      ]
    },
    {
      "id": "4d75a5b1-5227-41a4-87cc-67a5a8074f37",
      "name": "Upload File",
      "type": "n8n-nodes-base.form",
      "position": [
        1420,
        440
      ]
    },
    {
      "id": "5e5e3ece-00b3-4790-89e0-35d3c8d03b7d",
      "name": "Choose Workflow",
      "type": "n8n-nodes-base.form",
      "position": [
        2740,
        540
      ]
    },
    {
      "id": "7fcc236c-dd97-4a1e-bf3d-d85aba520938",
      "name": "Success",
      "type": "n8n-nodes-base.form",
      "position": [
        3700,
        1020
      ]
    },
    {
      "id": "27736a52-af15-47f8-8186-d486b2968256",
      "name": "Choose Instance",
      "type": "n8n-nodes-base.form",
      "position": [
        1420,
        620
      ]
    },
    {
      "id": "9b83c34d-0b0b-47bc-b4a7-27eed0e796fb",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        540,
        500
      ]
    },
    {
      "id": "f6d45cd9-a091-4c8b-8ef0-6815a1adb0f1",
      "name": "Generate Instance Options",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        620
      ]
    },
    {
      "id": "73717c97-4579-4e49-ac33-4aada3bcaf55",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1140,
        520
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Prepare a list of options for the next form"
      }
    },
    {
      "id": "0537d195-3885-4903-8a41-56915f7b64de",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1360,
        360
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 416.4415465717213,
        "content": "Request more input from the user"
      }
    },
    {
      "id": "43ee5820-e236-49f9-b89b-e4c5d4dd4188",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1580,
        520
      ],
      "parameters": {
        "width": 435.59135570107514,
        "height": 255.86856541619233,
        "content": "Map Settings to selected instance and retrieve all workflows from it"
      }
    },
    {
      "id": "53a42c23-af05-4e21-a936-14d2419b4530",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2020,
        440
      ],
      "parameters": {
        "width": 656.1389569291234,
        "height": 255.86856541619233,
        "content": "Prepare a list of options for the next form"
      }
    },
    {
      "id": "fd103846-04a6-4fb0-aba4-6230a85a7555",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2680,
        440
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Let the user choose a workflow from a list"
      }
    },
    {
      "id": "e58bdf1e-fcda-4b68-9798-24de0c7c6bd9",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3120,
        560
      ],
      "parameters": {
        "width": 875.9451799951569,
        "height": 216.1478580797073,
        "content": "Retrieve all credentials from this instance and convert the data to the final JSON format"
      }
    },
    {
      "id": "08855416-ca33-4344-b96b-4564d9841dfd",
      "name": "Get Selected Workflow",
      "type": "n8n-nodes-base.code",
      "position": [
        2960,
        620
      ]
    },
    {
      "id": "9a09a6b5-2b8d-461e-b63f-91100c3e7974",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2900,
        360
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 416.4415465717213,
        "content": "Convert the retrieved workflow into the final JSON format"
      }
    },
    {
      "id": "269c32c3-224b-42df-bd27-7718374cb343",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4000,
        420
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Combine the workflow and credential data to one item"
      }
    },
    {
      "id": "c9bbc713-3ac7-42d7-85c3-0c8aa22201d4",
      "name": "Split Out Nodes",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1060,
        1020
      ]
    },
    {
      "id": "e4c37af5-64de-4d40-9ff1-3a622ea40b86",
      "name": "Filter Out Nodes Having Credentials",
      "type": "n8n-nodes-base.filter",
      "position": [
        1280,
        1020
      ]
    },
    {
      "id": "bdb20dfd-1b47-4b50-a938-19f7790d180b",
      "name": "Extract Credentials",
      "type": "n8n-nodes-base.set",
      "position": [
        1500,
        1020
      ]
    },
    {
      "id": "554e0ee3-e722-4dcf-b82b-ea1ea59a037e",
      "name": "Remove Duplicate Credentials by Name",
      "type": "n8n-nodes-base.removeDuplicates",
      "position": [
        1720,
        1020
      ]
    },
    {
      "id": "0da2c486-ea7a-465b-b3cd-88e09e63c06b",
      "name": "Map Credentials",
      "type": "n8n-nodes-base.form",
      "position": [
        2160,
        1020
      ]
    },
    {
      "id": "8b92114e-6aa6-4404-a7f1-6224a45acdae",
      "name": "Get Selected Credentials",
      "type": "n8n-nodes-base.code",
      "position": [
        2380,
        1220
      ]
    },
    {
      "id": "bafcb91c-f441-40de-a1fd-7435206d991e",
      "name": "Add Old Names",
      "type": "n8n-nodes-base.set",
      "position": [
        2820,
        1020
      ]
    },
    {
      "id": "8da7f198-5e85-4d88-907e-1e35a55bdb96",
      "name": "Replace Credentials in Workflow",
      "type": "n8n-nodes-base.code",
      "position": [
        3260,
        1120
      ]
    },
    {
      "id": "f370d4fb-229e-4604-a1b1-c7c0cab8a32d",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        920
      ],
      "parameters": {
        "width": 875.6296366281999,
        "height": 257.0479807900252,
        "content": "Extract a list of all credentials from the workflow. The reference will be the old/existing name of the credential, since one workflow can contain multiple credentials of the same type."
      }
    },
    {
      "id": "31c0d4b7-4682-4db1-a453-0f1d69c58665",
      "name": "Sticky Note18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2100,
        920
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Let the user map every credential or create new ones"
      }
    },
    {
      "id": "d3c5edb1-74dc-4168-a987-84cdd54714cd",
      "name": "Generate Credential Options",
      "type": "n8n-nodes-base.code",
      "position": [
        1940,
        1020
      ]
    },
    {
      "id": "255ff6ab-d360-49dd-b63f-9f0d99278ae4",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1880,
        920
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 255.86856541619233,
        "content": "Prepare a list of options for the next form"
      }
    },
    {
      "id": "ae074b5a-d76a-4529-ba59-0d201dbd4e9e",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2320,
        920
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 456.12289999575364,
        "content": "Split mapped credentials into two streams, depending on wether they exist or not"
      }
    },
    {
      "id": "1b6d26af-9d6b-4865-bd81-8a5de49bc741",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2540,
        919.7999999999997
      ],
      "parameters": {
        "width": 435.95830414662703,
        "height": 276.068565416192,
        "content": "Create empty credentials if the option \"[create credential]\" was selected. and add the name of the originally assigned credential for future reference"
      }
    },
    {
      "id": "5ba8987a-7558-4fb8-94ef-ac2b81df5536",
      "name": "Create Empty Credentials",
      "type": "n8n-nodes-base.n8n",
      "position": [
        2600,
        1020
      ]
    },
    {
      "id": "7efa8f88-f5a0-47c8-8d12-2cb8c9b0e0c7",
      "name": "Get Missing Credentials",
      "type": "n8n-nodes-base.code",
      "position": [
        2380,
        1020
      ]
    },
    {
      "id": "2394952f-c6db-4c6e-8f62-080c952734c9",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2980,
        1020
      ],
      "parameters": {
        "width": 435.95830414662703,
        "height": 276.068565416192,
        "content": "Gather all new credential data and update the workflow accordingly. The oldName is being used as a reference during the search. "
      }
    },
    {
      "id": "4ee2a621-29c9-4d23-b222-0b31ff1cc903",
      "name": "Sticky Note23",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3420,
        1020
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 275.841854198618,
        "content": "Create the updated workflow on this instance"
      }
    },
    {
      "id": "e041c560-e847-472e-888e-0b6b3edb8998",
      "name": "Sticky Note24",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3640,
        920
      ],
      "parameters": {
        "width": 216.47293010628914,
        "height": 456.12289999575364,
        "content": "Provide feedback to the user wether the process was successful or not"
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "No Operation1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Generate Instance Options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Rename Keys": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Upload File": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No Operation": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Old Names": {
      "main": [
        [
          {
            "node": "Collect Credentials to Replace",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflows": {
      "main": [
        [
          {
            "node": "Split Out Workflows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "No Operation1": {
      "main": [
        [
          {
            "node": "Split Out Nodes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Binary to JSON": {
      "main": [
        [
          {
            "node": "Rename Keys",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Choose Instance": {
      "main": [
        [
          {
            "node": "Prepare Request Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Choose Workflow": {
      "main": [
        [
          {
            "node": "Get Selected Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Workflow": {
      "main": [
        [
          {
            "node": "Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Credentials": {
      "main": [
        [
          {
            "node": "Get Missing Credentials",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Selected Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Nodes": {
      "main": [
        [
          {
            "node": "Filter Out Nodes Having Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Export Credentials",
            "type": "main",
            "index": 0
          },
          {
            "node": "No Operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Export Credentials": {
      "main": [
        [
          {
            "node": "Get Credentials Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflow Names": {
      "main": [
        [
          {
            "node": "Choose Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Determine Workflow Source",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Credentials": {
      "main": [
        [
          {
            "node": "Remove Duplicate Credentials by Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Workflows": {
      "main": [
        [
          {
            "node": "Sort by updatedAt DESC",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Credentials Data": {
      "main": [
        [
          {
            "node": "Binary to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Request Data": {
      "main": [
        [
          {
            "node": "Get Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Selected Workflow": {
      "main": [
        [
          {
            "node": "Export Credentials",
            "type": "main",
            "index": 0
          },
          {
            "node": "No Operation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort by updatedAt DESC": {
      "main": [
        [
          {
            "node": "Get Workflow Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Missing Credentials": {
      "main": [
        [
          {
            "node": "Create Empty Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Empty Credentials": {
      "main": [
        [
          {
            "node": "Add Old Names",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Selected Credentials": {
      "main": [
        [
          {
            "node": "Collect Credentials to Replace",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Determine Workflow Source": {
      "main": [
        [
          {
            "node": "Upload File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Instance Options": {
      "main": [
        [
          {
            "node": "Choose Instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Credential Options": {
      "main": [
        [
          {
            "node": "Map Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect Credentials to Replace": {
      "main": [
        [
          {
            "node": "Replace Credentials in Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replace Credentials in Workflow": {
      "main": [
        [
          {
            "node": "Create Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Out Nodes Having Credentials": {
      "main": [
        [
          {
            "node": "Extract Credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicate Credentials by Name": {
      "main": [
        [
          {
            "node": "Generate Credential Options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}