{
  "name": "Simplitalk: exemplo de integração (API v1)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "simplitalk-lead",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "dbc2f3e5-c739-4f62-a033-8bf8ae85da1d",
      "name": "Lead do Simplitalk (webhook)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "ff888b52-e3f5-4d65-b4a3-82b1108c2ff1",
      "notes": "O Simplitalk manda aqui: nome, telefone, negocio_id, funil, etapa. Use esta URL (de produção) na automação 'Enviar para webhook'.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "ETAPA_AGENDADO",
              "value": "COLE-AQUI-O-ID-DA-ETAPA"
            },
            {
              "name": "ETAPA_DESQUALIFICADO",
              "value": "COLE-AQUI-O-ID-DA-ETAPA"
            }
          ]
        },
        "options": {}
      },
      "id": "92d80323-4da9-40bc-97e8-ec7dbca50594",
      "name": "Ids das etapas",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [
        0,
        -260
      ],
      "notes": "Pegue os ids no nó 'Listar funis e etapas' e cole aqui uma vez.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.simplitalk.com.br/v1/funis",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "867360a8-3764-4739-b518-6cf2197bbf12",
      "name": "Listar funis e etapas",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        -260
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      },
      "notes": "Rode uma vez para pegar os ids das etapas.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.simplitalk.com.br/v1/chave",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "efee9791-cfd0-4132-9e61-2e31444a8622",
      "name": "Conferir a chave",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        520,
        -260
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.simplitalk.com.br/v1/negocios/{{ $json.negocio_id }}/etapa",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"etapa_id\": \"{{ $('Ids das etapas').first().json.ETAPA_AGENDADO }}\",\n  \"comentario\": {{ JSON.stringify($json.resumo || \"Reunião agendada pelo agente de voz\") }}\n}"
      },
      "id": "72e9ce20-146d-43b3-8ce8-49c3c61b9dee",
      "name": "Agendado: mover e salvar resumo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.simplitalk.com.br/v1/negocios/{{ $('Lead do Simplitalk (webhook)').first().json.body.negocio_id }}/atividades",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"titulo\": \"Reunião agendada pelo agente de voz\",\n  \"tipo\": \"reuniao\",\n  \"prazo\": \"{{ $json.data_reuniao || '2026-12-03T15:00:00-03:00' }}\"\n}"
      },
      "id": "95425d53-125a-47d7-aa18-8645853ba78b",
      "name": "Agendado: criar a reunião",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        520,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      },
      "notes": "prazo em ISO com fuso, ex.: 2026-12-03T15:00:00-03:00",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.simplitalk.com.br/v1/negocios/{{ $json.negocio_id }}/etapa",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"etapa_id\": \"{{ $('Ids das etapas').first().json.ETAPA_DESQUALIFICADO }}\",\n  \"motivo_perda\": {{ JSON.stringify($json.motivo || \"Não qualificado\") }},\n  \"comentario\": {{ JSON.stringify($json.resumo || \"\") }}\n}"
      },
      "id": "b51927db-3312-4b71-a9de-154aa2925c13",
      "name": "Não qualificado: mover com motivo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.simplitalk.com.br/v1/negocios?telefone={{ $json.telefone }}&status=aberto",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "157cac66-5353-40cd-b6c0-34c316ea7c2f",
      "name": "Buscar negócio pelo telefone",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        400
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      },
      "notes": "Quando não tiver o negocio_id.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.simplitalk.com.br/v1/negocios",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"nome\": \"TESTE 3C {{ $now.toFormat('HHmmss') }}\",\n  \"telefone\": \"11900000000\"\n}"
      },
      "id": "82dd3984-a398-44fc-b38d-337cd323267f",
      "name": "Criar lead de teste",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        600
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      }
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://api.simplitalk.com.br/v1/negocios/{{ $json.negocio_id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"valor\": 1500,\n  \"email\": \"pessoa@exemplo.com\"\n}"
      },
      "id": "5033a92c-5c86-4abc-b4fa-824ff7b7bb7d",
      "name": "Editar negócio e contato",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        800
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Simplitalk API"
        }
      }
    }
  ],
  "connections": {
    "Ids das etapas": {
      "main": [
        [
          {
            "node": "Listar funis e etapas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Listar funis e etapas": {
      "main": [
        [
          {
            "node": "Conferir a chave",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agendado: mover e salvar resumo": {
      "main": [
        [
          {
            "node": "Agendado: criar a reunião",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}