> For the complete documentation index, see [llms.txt](https://docs.leadlinks.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.leadlinks.app/api-desenvolvedores/criar-lead.md).

# Criar lead (unificado)

`POST https://api.leadlinks.app/public/tracking/create-lead`

Cria **Contato + Empresa + Negociação** em uma única chamada. Ideal para integrações com **formulários**, **landing pages**, **telefonia** e ferramentas externas. Autenticado pela mesma chave (`x-api-key`).

{% hint style="info" %}
**Deduplicação inteligente:** o sistema procura contatos existentes por **telefone** (últimos 8 dígitos) ou **e-mail** (sem distinção de maiúsculas). Se encontrar, **só completa os campos faltantes** sem sobrescrever os dados existentes. Empresas são deduplicadas pelo **nome/domínio**.
{% endhint %}

## Campo obrigatório

* **`integration_source`** *(string, obrigatório)* — identifica a origem da integração (ex.: `"formulario-site"`, `"Telefone"`, `"whatsapp-site"`).
* Além disso, o **`contact`** precisa ter **`email`** ou **`phone`**.

## Estrutura completa

```json
{
  "integration_source": "formulario-site",
  "contact": {
    "name": "João Silva",
    "email": "joao@empresa.com",
    "phone": "+5511999999999",
    "position": "Diretor Comercial",
    "custom_fields": { "origem_lead": "indicacao", "cargo_nivel": "diretor" }
  },
  "company": {
    "name": "Empresa ABC Ltda",
    "domain": "empresaabc.com.br",
    "website": "https://empresaabc.com.br",
    "phone": "+551130000000",
    "industry": "Tecnologia",
    "size": "51-200",
    "address": "Rua Augusta, 1234",
    "city": "São Paulo",
    "state": "SP",
    "country": "Brasil",
    "description": "Empresa de software",
    "custom_fields": { "cnpj": "12.345.678/0001-90", "segmento": "SaaS" }
  },
  "deal": {
    "title": "Proposta Empresa ABC",
    "description": "Proposta para fornecimento de software ERP",
    "value": 15000.00,
    "temperature": "hot",
    "expected_close_date": "2024-06-15",
    "pipeline_id": "uuid-do-pipeline",
    "stage_id": "uuid-do-estagio",
    "custom_fields": { "ligacao": "completed", "valor_mensal": "5000" }
  },
  "consents": [
    { "type": "data_processing", "legal_basis": "consent", "notes": "Aceito via formulário do site" },
    { "type": "marketing", "legal_basis": "consent" }
  ],
  "utm": {
    "source": "google", "medium": "cpc", "campaign": "vendas-q1",
    "content": "banner-topo", "term": "crm vendas",
    "referrer": "https://www.google.com", "path": "/landing-page",
    "gclid": "CjwKCAiA...", "fbclid": null, "msclkid": null, "dclid": null
  },
  "conversion": {
    "type": "formulario", "host": "www.meusite.com.br",
    "path": "/contato", "element": "form-principal", "ip": "189.10.20.30"
  }
}
```

Resposta `200`:

```json
{
  "success": true,
  "contact_id": "550e8400-e29b-41d4-a716-446655440000",
  "company_id": "660e8400-e29b-41d4-a716-446655440001",
  "deal_id": "770e8400-e29b-41d4-a716-446655440002"
}
```

## Variações (payloads mínimos)

Só os blocos que você tiver são necessários — `integration_source` + `contact` (com email ou phone) já bastam.

### Telefone (mínimo)

```json
{ "integration_source": "Telefone", "contact": { "phone": "+551151185256" } }
```

### Rastreamento de telefonia

```json
{
  "integration_source": "Telefone",
  "contact": { "phone": "+551151185256" },
  "deal": {
    "title": "telefone - (11) 5118-5256",
    "custom_fields": { "ligacao": "completed", "ouvir_ligacao": "https://phonetrack.app/public/call/123" }
  },
  "utm": { "source": "google", "medium": "cpc", "campaign": "16889", "content": "25070" },
  "conversion": { "type": "telefone" }
}
```

### WhatsApp

```json
{
  "integration_source": "whatsapp-site",
  "contact": { "name": "Maria Santos", "phone": "+5511988887777" },
  "deal": { "title": "Maria Santos — +5511988887777" },
  "conversion": { "type": "whatsapp", "host": "www.meusite.com.br", "path": "/produto", "element": "botao-whatsapp" },
  "utmz_first": "utm_source=instagram,utm_medium=social,utm_campaign=promo",
  "utmz_last": "utm_source=google,utm_medium=cpc,utm_campaign=remarketing"
}
```

## Referência dos blocos

| Bloco                | Descrição                                                                                                                        |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `integration_source` | **Obrigatório.** Origem da integração.                                                                                           |
| `contact`            | `name`, `email`, `phone`, `position`, `custom_fields`. Precisa de email **ou** phone.                                            |
| `company`            | `name`, `domain`, `website`, `phone`, `industry`, `size`, `address`, `city`, `state`, `country`, `description`, `custom_fields`. |
| `deal`               | `title`, `description`, `value`, `temperature`, `expected_close_date`, `pipeline_id`, `stage_id`, `custom_fields`.               |
| `utm`                | `source`, `medium`, `campaign`, `content`, `term`, `path`, `referrer`, `gclid`, `fbclid`, `msclkid`, `dclid`.                    |
| `conversion`         | `type`, `host`, `path`, `element`, `ip`.                                                                                         |
| `consents`           | Lista de consentimentos LGPD: `type`, `legal_basis`, `notes`.                                                                    |

## Erros comuns

```json
// 400 — integration_source ausente
{ "error": "integration_source is required" }

// 400 — Contato sem email e sem phone
{ "error": "Contact must have at least email or phone" }

// 401 — Chave inválida
{ "error": "Invalid API key" }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.leadlinks.app/api-desenvolvedores/criar-lead.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
