{
  "name": "bubbl3: leads from Airtable",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "replace-with-a-long-random-value",
        "authentication": "headerAuth",
        "options": {}
      },
      "name": "Airtable sends here",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 0],
      "credentials": { "httpHeaderAuth": { "id": "", "name": "bubbl3 webhook header" } }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "t",
              "name": "t",
              "value": "={{ String(Math.floor(Date.now() / 1000)) }}",
              "type": "string"
            },
            {
              "id": "event_id",
              "name": "event_id",
              "value": "={{ (() => { const id = [$json.body.id]; if (id.some((v) => v === undefined || v === null || v === '')) throw new Error('No record id from Airtable'); return 'airtable-' + id.join('-'); })() }}",
              "type": "string"
            },
            {
              "id": "lead",
              "name": "lead",
              "value": "={{ JSON.stringify({ event_id: (() => { const id = [$json.body.id]; if (id.some((v) => v === undefined || v === null || v === '')) throw new Error('No record id from Airtable'); return 'airtable-' + id.join('-'); })(), phone: $json.body.phone, first_name: $json.body.first_name, last_name: $json.body.last_name, email: $json.body.email }) }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "Lead fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [300, 0]
    },
    {
      "parameters": {
        "action": "hmac",
        "type": "SHA256",
        "value": "={{ $json.t }}.{{ $json.lead }}",
        "dataPropertyName": "signature",
        "secret": "PASTE_THE_SOURCE_SECRET",
        "encoding": "hex"
      },
      "name": "Signature",
      "type": "n8n-nodes-base.crypto",
      "typeVersion": 1,
      "position": [600, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.bubbl3.com/v1/inbound/leads/PASTE_THE_SOURCE_ID",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "bubbl3-signature", "value": "=t={{ $json.t }},v1={{ $json.signature }}" },
            { "name": "Idempotency-Key", "value": "={{ $json.event_id }}" }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ $json.lead }}",
        "options": {}
      },
      "name": "Send the lead to bubbl3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 0]
    }
  ],
  "connections": {
    "Airtable sends here": { "main": [[{ "node": "Lead fields", "type": "main", "index": 0 }]] },
    "Lead fields": { "main": [[{ "node": "Signature", "type": "main", "index": 0 }]] },
    "Signature": { "main": [[{ "node": "Send the lead to bubbl3", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
