{
  "id": "jt8yrrFQMTCAvpe6URtUT",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Import contacts example",
  "tags": [],
  "nodes": [
    {
      "id": "90c72224-ada9-450b-a579-00d7b208909c",
      "name": "Import contacts from sales navigator search",
      "type": "n8n-nodes-sourcegeek.sourcegeek",
      "position": [
        704,
        80
      ],
      "parameters": {
        "url": "={{ $('On form submission').item.json['Search Results URL'] }}",
        "operation": "importContactsSalesNavSearch",
        "maxResults": 10
      },
      "credentials": {
        "sourcegeekCredentialsApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d8926517-a421-42ac-8e7e-d7c55abdfbc3",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        32,
        80
      ],
      "parameters": {
        "options": {},
        "formTitle": "Linked Search URL",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Search Results URL"
            }
          ]
        }
      },
      "typeVersion": 2.5
    },
    {
      "id": "82537be8-5fb9-4f37-9f2b-7c5b6393445c",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        256,
        80
      ],
      "parameters": {
        "jsCode": "// Get the URL from the previous node (adjust the field name if needed)\nconst url = $input.first().json['Search Results URL'];\n\n// Normalize\nconst normalizedUrl = url.toLowerCase();\n\nlet linkedinType = \"unknown\";\n\nif (normalizedUrl.includes(\"linkedin.com/sales/\")) {\n  linkedinType = \"sales_navigator\";\n} \nelse if (normalizedUrl.includes(\"linkedin.com/talent/\")) {\n  linkedinType = \"recruiter\";\n} \nelse if (normalizedUrl.includes(\"linkedin.com/search/\")) {\n  linkedinType = \"basic\";\n}\n\n// Return value for Switch node\nreturn [\n  {\n    json: {\n      linkedinType: linkedinType,\n      originalUrl: url\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "21e06fff-ebe3-49e1-85c1-2b04d07bf18d",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        480,
        64
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7d72f17f-8750-43cf-a68d-1143015c87fc",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.linkedinType }}",
                    "rightValue": "basic"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "ca2e815d-ba86-4a7f-a622-49bac49392f5",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.linkedinType }}",
                    "rightValue": "sales_navigator"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "66da0317-b56d-4f21-bc16-e75df53f3ef7",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.linkedinType }}",
                    "rightValue": "recruiter"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "c6229a53-5aa3-4a55-a236-cbd7790595df",
      "name": "Import contacts from basic search",
      "type": "n8n-nodes-sourcegeek.sourcegeek",
      "position": [
        704,
        -112
      ],
      "parameters": {
        "url": "={{ $('On form submission').item.json['Search Results URL'] }}",
        "operation": "importContactsBasicSearch",
        "maxResults": 10
      },
      "credentials": {
        "sourcegeekCredentialsApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f385b525-a4ec-4504-83bf-008316e7ea85",
      "name": "Import contacts from recruiter search",
      "type": "n8n-nodes-sourcegeek.sourcegeek",
      "position": [
        704,
        272
      ],
      "parameters": {
        "url": "={{ $('On form submission').item.json['Search Results URL'] }}",
        "operation": "importContactsRecruiterSearch",
        "maxResults": 10
      },
      "credentials": {
        "sourcegeekCredentialsApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "54d17f29-3ca5-4b49-bfa1-85670159fa6d",
      "name": "Get tool run ID",
      "type": "n8n-nodes-sourcegeek.sourcegeek",
      "position": [
        1152,
        80
      ],
      "parameters": {
        "operation": "getToolRun",
        "toolRunId": "={{ $('Get_Run_ID').item.json.sourcegeek.runId }}"
      },
      "credentials": {
        "sourcegeekCredentialsApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": false,
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "d4c77638-f47d-455c-9be4-84050d781123",
      "name": "Get_Run_ID",
      "type": "n8n-nodes-base.code",
      "position": [
        928,
        80
      ],
      "parameters": {
        "jsCode": "let linkedinType = $('Code in JavaScript').first().json.linkedinType;\nlet runId = \"\";\n\n// Switch to assign Run ID per type\nswitch (linkedinType) {\n  case \"basic\":\n    runId = $input.first().json.data.toolRunId;\n    break;\n\n  case \"sales_navigator\":\n    runId = $input.first().json.data.toolRunId;\n    break;\n\n  case \"recruiter\":\n    runId = $input.first().json.data.toolRunId;\n    break;\n\n  default:\n    runId = \"RUN_UNKNOWN_001\";\n}\n\n// Return everything for downstream nodes\nreturn [\n  {\n    json: {\n      sourcegeek: {\n        linkedinType,\n        runId\n      }\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "1b1a84b7-2cae-4c42-9380-5a21a3b4033b",
      "name": "Append row in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1824,
        -40
      ],
      "parameters": {
        "columns": {
          "value": {
            "Company": "={{ $json.companyName }}",
            "Location": "={{ $json.location }}",
            "Job title": "={{ $json.jobTitle }}",
            "Last name": "={{ $json.lastName }}",
            "First name": "={{ $json.firstName }}",
            "LinkedIn url": "={{ $json.linkedinProfileUrl }}",
            "Profile image URL": "={{ $json.profileImageUrl }}"
          },
          "schema": [
            {
              "id": "First name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "First name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Last name",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Last name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Profile image",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Profile image",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "LinkedIn url",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "LinkedIn url",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Location",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Location",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Job title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Job title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Company",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Profile image URL",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Profile image URL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FaS-VuTd-vokZwWOh_W_Vlwjp1PgYFe2Ak2JpntC1_Y/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1FaS-VuTd-vokZwWOh_W_Vlwjp1PgYFe2Ak2JpntC1_Y",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1FaS-VuTd-vokZwWOh_W_Vlwjp1PgYFe2Ak2JpntC1_Y/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Import"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "f377ba77-c413-4ad6-9581-d31036f2da20",
      "name": "If Job Run is Complete",
      "type": "n8n-nodes-base.if",
      "position": [
        1376,
        8
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "320e2bb5-2653-4ef2-aec2-36326951f50b",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "=COMPLETED"
            }
          ]
        }
      },
      "typeVersion": 2.3,
      "alwaysOutputData": false
    },
    {
      "id": "b4ae3f0a-2704-4951-8742-f3b8c726ad3a",
      "name": "Convert to array for insert",
      "type": "n8n-nodes-base.code",
      "position": [
        1600,
        -40
      ],
      "parameters": {
        "jsCode": "// n8n Code node (Run once for each item)\n\n// Your input is an array of items; in n8n Code node you usually get them via $input.all()\nconst items = $input.all();\n\nconst output = [];\n\nfor (const item of items) {\n  const data = item.json?.data || {};\n  const contacts = Array.isArray(data.contacts) ? data.contacts : [];\n\n  const runId = data.toolRunId || \"\";\n  const searchId = data.id || \"\";\n  const status = item.json?.status || \"\";\n\n  for (const c of contacts) {\n    output.push({\n      json: {\n        // run context (useful for traceability)\n        toolRunId: runId,\n        searchId,\n        status,\n\n        // contact fields (map these to your sheet columns)\n        contactId: c.id || \"\",\n        createdAt: c.createdAt || \"\",\n        updatedAt: c.updatedAt || \"\",\n        firstName: c.firstName || \"\",\n        lastName: c.lastName || \"\",\n        email: c.email || \"\",\n        phone: c.phone || \"\",\n        description: c.description || \"\",\n        profileImageUrl: c.profileImageUrl || \"\",\n        linkedinId: c.linkedinId || \"\",\n        linkedinUsername: c.linkedinUsername || \"\",\n        linkedinProfileUrl: c.linkedinUsername ? `https://www.linkedin.com/in/${c.linkedinUsername}` : \"\",\n        location: c.location || \"\",\n        jobTitle: c.jobTitle || \"\",\n        companyName: c.companyName || \"\",\n        companyIndustry: c.companyIndustry || \"\",\n        companyLocation: c.companyLocation || \"\",\n      }\n    });\n  }\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "3fd662bd-5b22-4ccd-b5f4-e5d461341a71",
      "name": "Wait until job is completed",
      "type": "n8n-nodes-base.wait",
      "position": [
        1600,
        176
      ],
      "parameters": {},
      "typeVersion": 1.1,
      "alwaysOutputData": true
    },
    {
      "id": "a7ab59cc-8493-4f0e-8d07-2bff1dc8b620",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        -160
      ],
      "parameters": {
        "width": 272,
        "height": 480,
        "content": "## How it works\nThis workflow can be used to retrieve search results of any LinkedIn platform and append them in a Google Sheet.\n\nFor sending the message from your LinkedIn profile to another LinkedIn user, the SourceGeek node is being used.\n\nAfter the message is successfully sent, the initial row in the Google Sheet will be updated with a timestamp."
      },
      "typeVersion": 1
    },
    {
      "id": "ec6e59b6-759f-4d51-916e-c796928e78cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -72,
        -192
      ],
      "parameters": {
        "color": 7,
        "width": 2096,
        "height": 624,
        "content": "## Getting search results from LinkedIn and placing them in a Google Sheet"
      },
      "typeVersion": 1
    },
    {
      "id": "866289b6-cc1f-4211-a334-9d67baa582b1",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 128,
        "content": "Fill in a LinkedIn search results page from Basic, Sales Navigator or Recruiter"
      },
      "typeVersion": 1
    },
    {
      "id": "36abfc42-f0fa-4572-a281-4b055fe2dbc5",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        -80
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 128,
        "content": "Check, based on the url, which Action should be taken"
      },
      "typeVersion": 1
    },
    {
      "id": "c4a9354b-23f9-4056-846e-e8b0e6cf8d8b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        -64
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 128,
        "content": "Loop through this Action which wait untill the complete list is generated"
      },
      "typeVersion": 1
    },
    {
      "id": "e36875b1-cbfe-47aa-86e0-8d8ef6bd358d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        -144
      ],
      "parameters": {
        "color": 5,
        "width": 256,
        "height": 80,
        "content": "When ready, convert the output and append the data to rows in a Google Sheet"
      },
      "typeVersion": 1
    },
    {
      "id": "df4cce78-74dd-4f95-be21-05feaafbc2f4",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1776,
        176
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 128,
        "content": "If not ready. wait 5 seconds and try again"
      },
      "typeVersion": 1
    },
    {
      "id": "0a861c69-81e7-4237-9a4f-613c7d6febcf",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        -64
      ],
      "parameters": {
        "color": 5,
        "width": 160,
        "height": 128,
        "content": "Returns a Run ID while the actual 'list generating' is happening in the background"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "2282dce8-7389-4a37-8b1e-4f45a880b3ed",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Import contacts from basic search",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Import contacts from sales navigator search",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Import contacts from recruiter search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get_Run_ID": {
      "main": [
        [
          {
            "node": "Get tool run ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get tool run ID": {
      "main": [
        [
          {
            "node": "If Job Run is Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet": {
      "main": [
        []
      ]
    },
    "If Job Run is Complete": {
      "main": [
        [
          {
            "node": "Convert to array for insert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait until job is completed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to array for insert": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait until job is completed": {
      "main": [
        [
          {
            "node": "Get tool run ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Import contacts from basic search": {
      "main": [
        [
          {
            "node": "Get_Run_ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Import contacts from recruiter search": {
      "main": [
        [
          {
            "node": "Get_Run_ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Import contacts from sales navigator search": {
      "main": [
        [
          {
            "node": "Get_Run_ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}