{
  "name": "GTMMAXING - Find work emails for LinkedIn profiles",
  "nodes": [
    {
      "parameters": {},
      "id": "6f1d7c1e-0001-4c55-9d2a-0a0000000001",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Replace this node with your source: Google Sheets, HubSpot, Airtable, a webhook...\n// Each item needs a `linkedin` field with a profile URL.\nreturn [\n  { json: { linkedin: 'https://www.linkedin.com/in/REPLACE-ME' } },\n];"
      },
      "id": "6f1d7c1e-0002-4c55-9d2a-0a0000000002",
      "name": "LinkedIn profiles",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.gtmmaxing.com/v1/agent/tools/gtm_find_contacts",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ people: [$json.linkedin], verify: false, max_credits: 1, idempotency_key: 'n8n-email-' + $json.linkedin.hash('sha256') }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 300
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-GTM-Source",
              "value": "n8n"
            }
          ]
        }
      },
      "id": "6f1d7c1e-0003-4c55-9d2a-0a0000000003",
      "name": "Find email",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        300
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "id": "gtmmaxingApiKey01",
          "name": "GTMMAXING API key"
        }
      },
      "notes": "1 credit per email found. Misses and repeats are free. Set verify: true and max_credits: 3 to mailbox-check."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "6f1d7c1e-c0d1-4c55-9d2a-0a00000000c1",
              "leftValue": "={{ $json.answer.status }}",
              "rightValue": "running",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "6f1d7c1e-0004-4c55-9d2a-0a0000000004",
      "name": "Still running?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        300
      ]
    },
    {
      "parameters": {
        "amount": 4,
        "unit": "seconds"
      },
      "id": "6f1d7c1e-0005-4c55-9d2a-0a0000000005",
      "name": "Wait 4s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        880,
        160
      ],
      "webhookId": "6f1d7c1e-0005-4c55-9d2a-0a00000000w1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.gtmmaxing.com/v1/agent/tools/gtm_results",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ run_id: $json.answer.run_id }) }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-GTM-Source",
              "value": "n8n"
            }
          ]
        }
      },
      "id": "6f1d7c1e-0006-4c55-9d2a-0a0000000006",
      "name": "Check run (free)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        160
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "id": "gtmmaxingApiKey01",
          "name": "GTMMAXING API key"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Turns each GTMMAXING answer into a flat row. Values are looked up by column name.\nreturn $input.all().map((item, i) => {\n  const a = item.json.answer || {};\n  const row = a.rows && a.rows[0] ? a.rows[0] : [];\n  const get = (name) => { const k = (a.columns || []).indexOf(name); return k > -1 ? row[k] : null; };\n  let linkedin = null;\n  try { linkedin = $('LinkedIn profiles').itemMatching(i).json.linkedin; } catch (e) {}\n  return { json: {\n    linkedin,\n    name: get('name'),\n    email: get('email'),\n    verdict: get('verdict'),\n    status: a.status,\n    reason: a.reason || null,\n    summary: a.summary,\n    cost: a.cost,\n    balance: a.balance,\n    run_id: a.run_id,\n  }, pairedItem: { item: i } };\n});"
      },
      "id": "6f1d7c1e-0007-4c55-9d2a-0a0000000007",
      "name": "Email row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        880,
        420
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "LinkedIn profiles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LinkedIn profiles": {
      "main": [
        [
          {
            "node": "Find email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find email": {
      "main": [
        [
          {
            "node": "Still running?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Still running?": {
      "main": [
        [
          {
            "node": "Wait 4s",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 4s": {
      "main": [
        [
          {
            "node": "Check run (free)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check run (free)": {
      "main": [
        [
          {
            "node": "Still running?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
