{
  "nodes": [
    {
      "id": "28f1880b-7ebd-4cf6-9e58-cbb299120bfe",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1760,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "af49496d-8388-4de6-9e56-9d3575c0baf5",
      "name": "Set Search Parameters",
      "type": "n8n-nodes-base.set",
      "notes": "Configure your search parameters here:\n- keywords: Search terms\n- location: Geographic filter\n- title: Job title filter\n- limit: Max results",
      "position": [
        1984,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "search-keywords",
              "name": "keywords",
              "type": "string",
              "value": "CEO SaaS"
            },
            {
              "id": "search-location",
              "name": "location",
              "type": "string",
              "value": "United States"
            },
            {
              "id": "search-title",
              "name": "title",
              "type": "string",
              "value": "Head of Growth"
            },
            {
              "id": "results-limit",
              "name": "limit",
              "type": "string",
              "value": "100"
            }
          ]
        }
      },
      "notesInFlow": true,
      "typeVersion": 3.4
    },
    {
      "id": "d09c54f3-8fe2-4047-9d34-d0cbe4c35a51",
      "name": "Search LinkedIn People",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Calls ConnectSafely.ai API\nPOST /linkedin/search/people",
      "position": [
        2208,
        480
      ],
      "parameters": {
        "url": "https://api.connectsafely.ai/linkedin/search/people",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "jsonBody": "={\n  \"keywords\": \"{{ $json.keywords }}\",\n  \"location\": \"{{ $json.location }}\",\n  \"title\": \"{{ $json.title }}\",\n  \"limit\": {{ $json.limit }}\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        },
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "b7a0fb54-d629-4569-9a74-1666a6ab2ea3",
      "name": "Format Results",
      "type": "n8n-nodes-base.code",
      "notes": "Normalizes API response to match PhantomBuster export format",
      "position": [
        2432,
        480
      ],
      "parameters": {
        "jsCode": "// Process ConnectSafely.ai API response\n// Response: [{ success: true, people: [...], pagination: {...}, hasMore: bool }]\n\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const response = item.json;\n  \n  // Handle array wrapper - API returns array with single object\n  const data = Array.isArray(response) ? response[0] : response;\n  \n  if (!data || !data.success) {\n    continue;\n  }\n  \n  // Get the people array from response\n  const people = data.people || [];\n  \n  for (const person of people) {\n    // Extract company from headline if present (e.g., \"CEO at Company Name\")\n    let company = '';\n    const headline = person.headline || person.currentPosition || '';\n    const atMatch = headline.match(/(?:at|@|-)\\s*([^|\u2022]+?)(?:\\s*\\||\\s*\u2022|$)/i);\n    if (atMatch) {\n      company = atMatch[1].trim();\n    }\n    \n    results.push({\n      json: {\n        // Profile URL and IDs\n        profileUrl: person.profileUrl || '',\n        profileId: person.profileId || '',\n        profileUrn: person.profileUrn || '',\n        \n        // Name\n        fullName: `${person.firstName || ''} ${person.lastName || ''}`.trim(),\n        firstName: person.firstName || '',\n        lastName: person.lastName || '',\n        \n        // Professional info\n        headline: person.headline || '',\n        currentPosition: person.currentPosition || '',\n        company: company,\n        \n        // Location\n        location: person.location || '',\n        \n        // Network\n        connectionDegree: person.connectionDegree || '',\n        \n        // Status flags\n        isPremium: person.isPremium || false,\n        isOpenToWork: person.isOpenToWork || false,\n        \n        // Profile picture\n        profilePicture: person.profilePicture || '',\n        \n        // Timestamp\n        extractedAt: new Date().toISOString()\n      }\n    });\n  }\n}\n\nif (results.length === 0) {\n  return [{ json: { error: 'No results found', timestamp: new Date().toISOString() } }];\n}\n\nreturn results;"
      },
      "notesInFlow": true,
      "typeVersion": 2
    },
    {
      "id": "1bcd053d-40a5-4576-b4f1-36ad29ab7015",
      "name": "Export to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2656,
        384
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "profileUrl",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "profileUrl",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "fullName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "fullName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "firstName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "firstName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lastName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lastName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "headline",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "headline",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "currentTitle",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "currentTitle",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "location",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "location",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "connectionDegree",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "connectionDegree",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "isPremium",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "isPremium",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "isOpenToWork",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "isOpenToWork",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "industry",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "industry",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "connectionsCount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "connectionsCount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "profilePicture",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "profilePicture",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "extractedAt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "extractedAt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "searchType",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "searchType",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "profileId",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "profileId",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rSor29CdaLpmtLCFaJhFaMwBYA-Ih1PeuG3iw1iHy5E/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1rSor29CdaLpmtLCFaJhFaMwBYA-Ih1PeuG3iw1iHy5E",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1rSor29CdaLpmtLCFaJhFaMwBYA-Ih1PeuG3iw1iHy5E/edit?usp=drivesdk",
          "cachedResultName": "LinkedIn Search Export Data"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "279651ee-0161-4822-802d-997799a69eaa",
      "name": "Export to JSON",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        2656,
        576
      ],
      "parameters": {
        "options": {
          "fileName": "=linkedin-export-{{ $now.format('yyyy-MM-dd-HHmmss') }}.json"
        },
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "74860d01-9825-4f0c-8c4d-6c2c9b4807fd",
      "name": "Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1152,
        112
      ],
      "parameters": {
        "width": 548,
        "height": 752,
        "content": "@[youtube](N4kZ3YiLh2Q)\n\n### How it works\nSearches LinkedIn via ConnectSafely.ai API (no cookies needed), formats results, and exports to Google Sheets or JSON.\n\n### Setup steps\n1. **Get API key** at [connectsafely.ai/dashboard](https://connectsafely.ai/dashboard) \u2192 Settings \u2192 API Keys\n2. **Add credentials:**\n   - HTTP Bearer Auth with your API key\n   - Google Sheets OAuth2\n3. **Configure search** in the Set Parameters node\n4. **Update Sheet ID** in Export node with your spreadsheet\n\n### Features\n\u2705 Search by keywords, location, title  \n\u2705 Platform-compliant (no ban risk)  \n\u2705 Up to 100+ results per search  \n\u2705 Dual export: Sheets + JSON"
      },
      "typeVersion": 1
    },
    {
      "id": "a5ff8239-3ecc-4305-9fc7-787e8f2c4241",
      "name": "1\ufe0f\u20e3 Search",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1912,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 256,
        "content": "**Search** \u2014 Configure parameters and call ConnectSafely.ai API"
      },
      "typeVersion": 1
    },
    {
      "id": "7c99c081-fe06-41f9-bbd6-b74c1c06f45c",
      "name": "2\ufe0f\u20e3 Export",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2560,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 464,
        "content": "**Export** \u2014 Format results and save to Sheets/JSON"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Format Results": {
      "main": [
        [
          {
            "node": "Export to Google Sheets",
            "type": "main",
            "index": 0
          },
          {
            "node": "Export to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Search Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Search Parameters": {
      "main": [
        [
          {
            "node": "Search LinkedIn People",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search LinkedIn People": {
      "main": [
        [
          {
            "node": "Format Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}