{
  "name": "SoftSales - Receber lead externo",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "softsales-lead",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "0e47c7c5-6149-48a4-b72a-1b5370da5e51",
      "name": "Receber lead",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [-520, 0],
      "webhookId": "32d021ef-b61b-40ab-a0f2-0b0918c5c1aa"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "external_id",
              "value": "={{ $json.body.external_id || $json.body.id || $execution.id }}",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "name",
              "value": "={{ $json.body.name || $json.body.nome }}",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "email",
              "value": "={{ $json.body.email || '' }}",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "phone",
              "value": "={{ $json.body.phone || $json.body.telefone || $json.body.whatsapp || '' }}",
              "type": "string"
            },
            {
              "id": "a5",
              "name": "company",
              "value": "={{ $json.body.company || $json.body.empresa || '' }}",
              "type": "string"
            },
            {
              "id": "a6",
              "name": "source",
              "value": "={{ $json.body.source || $json.body.origem || 'n8n' }}",
              "type": "string"
            },
            {
              "id": "a7",
              "name": "value",
              "value": "={{ Number($json.body.value || $json.body.valor || 0) }}",
              "type": "number"
            },
            {
              "id": "a8",
              "name": "tracking",
              "value": "={{ $json.body.tracking || { utm_source: $json.body.utm_source, utm_campaign: $json.body.utm_campaign } }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "42e780fd-c6e5-4ce3-9932-f6883cb1dcbf",
      "name": "Mapear campos",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-280, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://SUA-EMPRESA.softsales.com.br/api/v1/inbox/SEU_ENDPOINT_ID",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer SEU_SEGREDO"
            },
            {
              "name": "Idempotency-Key",
              "value": "={{ $json.external_id }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "raw",
        "rawContentType": "application/json",
        "body": "={{ JSON.stringify({ external_id: $json.external_id, name: $json.name, email: $json.email || null, phone: $json.phone || null, company: $json.company || null, source: $json.source, value: $json.value, tracking: $json.tracking, custom_fields: {} }) }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "096fe460-8edf-4645-b3b4-b3d3a93e53e4",
      "name": "Enviar ao SoftSales",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-20, 0]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { ok: true, softsales: $json } }}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "68b2990e-9954-4af7-84b4-c572883e7a0c",
      "name": "Responder origem",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [240, 0]
    }
  ],
  "pinData": {},
  "connections": {
    "Receber lead": {
      "main": [[{ "node": "Mapear campos", "type": "main", "index": 0 }]]
    },
    "Mapear campos": {
      "main": [[{ "node": "Enviar ao SoftSales", "type": "main", "index": 0 }]]
    },
    "Enviar ao SoftSales": {
      "main": [[{ "node": "Responder origem", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ba03f1de-b001-4f15-8025-928508c66ae1",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
