{
  "name": "LinkedIn profiles through Datacircle",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ],
      "id": "8b769fba-0689-46fa-8768-b8285cba1f39"
    },
    {
      "parameters": {
        "jsCode": "// Your list: swap this node for Google Sheets, Airtable or your CRM. Each item needs a linkedin_url\nreturn [\n  { json: { linkedin_url: 'https://www.linkedin.com/in/williamhgates' } },\n  { json: { linkedin_url: 'https://www.linkedin.com/in/satyanadella' } },\n];"
      },
      "name": "LinkedIn URLs",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        300
      ],
      "id": "56043b69-dcf0-464b-9653-4a06683c6ee8"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.datacircle.dev/v1/profiles/enrich",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Data-Provider",
              "value": "up2data"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $json.linkedin_url }}"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1000
            }
          },
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "name": "Up2Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "datacircle",
          "name": "Datacircle API key"
        }
      },
      "id": "71dd5be5-3c66-4982-8e15-f2421444e60a"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "Found",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 200,
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Found"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "Not found",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 422,
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Not found"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "Not a profile URL",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 400,
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Not a profile URL"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "Daily limit",
                    "leftValue": "={{ $json.statusCode }}",
                    "rightValue": 429,
                    "operator": {
                      "type": "number",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "Daily limit"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Other"
        }
      },
      "name": "Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        660,
        300
      ],
      "id": "ba189a31-7034-44fd-b276-b6822e3b9350"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "linkedin_url",
              "name": "linkedin_url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}",
              "type": "string"
            },
            {
              "id": "status",
              "name": "status",
              "value": "found",
              "type": "string"
            },
            {
              "id": "full_name",
              "name": "full_name",
              "value": "={{ $json.body.data.full_name }}",
              "type": "string"
            },
            {
              "id": "headline",
              "name": "headline",
              "value": "={{ $json.body.data.headline }}",
              "type": "string"
            },
            {
              "id": "location",
              "name": "location",
              "value": "={{ $json.body.data.location?.raw }}",
              "type": "string"
            },
            {
              "id": "company",
              "name": "company",
              "value": "={{ $json.body.data.current_company?.name }}",
              "type": "string"
            },
            {
              "id": "title",
              "name": "title",
              "value": "={{ $json.body.data.current_company?.title }}",
              "type": "string"
            },
            {
              "id": "industry",
              "name": "industry",
              "value": "={{ $json.body.data.current_company?.industry }}",
              "type": "string"
            },
            {
              "id": "headcount",
              "name": "headcount",
              "value": "={{ $json.body.data.current_company?.headcount }}",
              "type": "string"
            },
            {
              "id": "cost_usd",
              "name": "cost_usd",
              "value": "={{ $json.body.datacircle_meta.cost_usd }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "name": "Profile",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        60
      ],
      "id": "060aadbc-97e1-410c-8e34-1bbd795d86f7"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "linkedin_url",
              "name": "linkedin_url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}",
              "type": "string"
            },
            {
              "id": "status",
              "name": "status",
              "value": "not found: private or deleted, free",
              "type": "string"
            },
            {
              "id": "cost_usd",
              "name": "cost_usd",
              "value": "=0",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "name": "Not found",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        220
      ],
      "id": "691de353-8b2a-4ba1-b765-109c622f9384"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "linkedin_url",
              "name": "linkedin_url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}",
              "type": "string"
            },
            {
              "id": "status",
              "name": "status",
              "value": "not a profile URL, free",
              "type": "string"
            },
            {
              "id": "cost_usd",
              "name": "cost_usd",
              "value": "=0",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "name": "Not a profile URL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        380
      ],
      "id": "c8d165db-191c-4828-b6b3-04000d107d98"
    },
    {
      "parameters": {
        "url": "https://api.datacircle.dev/linkedin/profile",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Data-Provider",
              "value": "harvestapi"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 1000
            }
          },
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "name": "HarvestAPI",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        900,
        540
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "datacircle",
          "name": "Datacircle API key"
        }
      },
      "id": "91c694f0-33fb-4016-a874-b08de44f4037"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "linkedin_url",
              "name": "linkedin_url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}",
              "type": "string"
            },
            {
              "id": "status",
              "name": "status",
              "value": "={{ $json.statusCode !== 200 ? 'error ' + $json.statusCode + ': ' + $json.body.error : $json.body.element ? 'found (HarvestAPI)' : 'not found (HarvestAPI)' }}",
              "type": "string"
            },
            {
              "id": "full_name",
              "name": "full_name",
              "value": "={{ [$json.body.element?.firstName, $json.body.element?.lastName].filter(Boolean).join(' ') }}",
              "type": "string"
            },
            {
              "id": "headline",
              "name": "headline",
              "value": "={{ $json.body.element?.headline }}",
              "type": "string"
            },
            {
              "id": "location",
              "name": "location",
              "value": "={{ $json.body.element?.location?.linkedinText }}",
              "type": "string"
            },
            {
              "id": "company",
              "name": "company",
              "value": "={{ $json.body.element?.currentPosition?.[0]?.companyName }}",
              "type": "string"
            },
            {
              "id": "title",
              "name": "title",
              "value": "={{ $json.body.element?.currentPosition?.[0]?.position }}",
              "type": "string"
            },
            {
              "id": "cost_usd",
              "name": "cost_usd",
              "value": "={{ $json.body.datacircle_meta?.cost_usd ?? 0 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "name": "Profile from HarvestAPI",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1120,
        540
      ],
      "id": "86b105cb-ad8c-462d-9763-1359a14ebd9e"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "linkedin_url",
              "name": "linkedin_url",
              "value": "={{ $('LinkedIn URLs').item.json.linkedin_url }}",
              "type": "string"
            },
            {
              "id": "status",
              "name": "status",
              "value": "={{ 'error ' + $json.statusCode + ': ' + ($json.body.error?.message ?? $json.body.error) }}",
              "type": "string"
            },
            {
              "id": "cost_usd",
              "name": "cost_usd",
              "value": "=0",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "name": "Error",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        700
      ],
      "id": "20530bb8-f0a3-4dd3-bb77-de5b082a2358"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "LinkedIn URLs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LinkedIn URLs": {
      "main": [
        [
          {
            "node": "Up2Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Up2Data": {
      "main": [
        [
          {
            "node": "Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status": {
      "main": [
        [
          {
            "node": "Profile",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not found",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not a profile URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HarvestAPI",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HarvestAPI": {
      "main": [
        [
          {
            "node": "Profile from HarvestAPI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
