> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leavo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gerenciar Webhooks

> Listar, obter, atualizar e deletar webhooks

## Listar Webhooks

<Card>
  <strong>GET</strong> `/backend/webhooks`
</Card>

Retorna todos os webhooks configurados.

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.leavo.ai/backend/webhooks" \
    -H "Authorization: Bearer sua_chave_aqui"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  [
    {
      "id": "uuid",
      "name": "Webhook Formulário",
      "type": "inbound",
      "webhook_token": "abc123",
      "is_active": true,
      "total_calls": 150,
      "last_triggered": "2024-01-15T10:30:00Z"
    },
    {
      "id": "uuid",
      "name": "Notificar CRM",
      "type": "outbound",
      "target_url": "https://crm.exemplo.com/api",
      "is_active": true,
      "total_calls": 75,
      "last_triggered": "2024-01-15T09:00:00Z"
    }
  ]
  ```
</ResponseExample>

***

## Obter Webhook

<Card>
  <strong>GET</strong> `/backend/webhooks/{id}`
</Card>

Retorna detalhes completos de um webhook específico.

<ParamField path="id" type="string" required>
  UUID do webhook
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://api.leavo.ai/backend/webhooks/uuid-do-webhook" \
    -H "Authorization: Bearer sua_chave_aqui"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": "uuid",
    "tenant_id": "uuid",
    "name": "Webhook Formulário Site",
    "description": "Recebe leads do formulário do site",
    "type": "inbound",
    "webhook_token": "abc123xyz",
    "is_active": true,
    "field_mapping": {
      "name": "form.nome_completo",
      "email": "form.email",
      "phone": "form.telefone"
    },
    "custom_field_mapping": {
      "interesse": "form.produto_interesse"
    },
    "default_status_id": "uuid",
    "default_tags": ["uuid-1", "uuid-2"],
    "total_calls": 150,
    "last_triggered": "2024-01-15T10:30:00Z",
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-10T00:00:00Z"
  }
  ```
</ResponseExample>

***

## Atualizar Webhook

<Card>
  <strong>PUT</strong> `/backend/webhooks/{id}`
</Card>

Atualiza um webhook existente.

<ParamField path="id" type="string" required>
  UUID do webhook
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT "https://api.leavo.ai/backend/webhooks/uuid-do-webhook" \
    -H "Authorization: Bearer sua_chave_aqui" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Webhook Formulário Atualizado",
      "is_active": false
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": "uuid",
    "name": "Webhook Formulário Atualizado",
    "is_active": false,
    // ... outros campos
  }
  ```
</ResponseExample>

***

## Deletar Webhook

<Card>
  <strong>DELETE</strong> `/backend/webhooks/{id}`
</Card>

Remove um webhook permanentemente.

<ParamField path="id" type="string" required>
  UUID do webhook
</ParamField>

<Warning>
  Esta ação é irreversível. Certifique-se de que não há integrações dependendo deste webhook.
</Warning>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://api.leavo.ai/backend/webhooks/uuid-do-webhook" \
    -H "Authorization: Bearer sua_chave_aqui"
  ```
</RequestExample>

<ResponseExample>
  ```json 204 No Content theme={null}
  // Sem conteúdo
  ```
</ResponseExample>

***

## Regenerar Token

Para webhooks inbound, você pode regenerar o token de segurança:

```bash theme={null}
curl -X POST "https://api.leavo.ai/backend/webhooks/uuid-do-webhook/regenerate-token" \
  -H "Authorization: Bearer sua_chave_aqui"
```

<Warning>
  Ao regenerar o token, a URL antiga do webhook deixará de funcionar. Atualize suas integrações.
</Warning>
