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

# Atualizar um endpoint de webhook

> Atualiza URL, nome ou tipos exatos de evento de um webhook_endpoint; events_from e secret não mudam por este endpoint.

Atualiza um `webhook_endpoint` por **merge**: só os campos enviados mudam;
os demais ficam como estão. Podem mudar `name`, `url` e `events`.

`events_from` é **imutável** — enviá-lo com um valor diferente do atual
retorna `400`. Para trocar de fluxo, crie outro endpoint. O `secret` também
não muda por aqui: para trocá-lo, use "Resetar Secret" no dashboard.

Este endpoint aceita [`Idempotency-Key`](/api-reference/idempotency).

## Autenticação

Use a API key da organização com escopo `write`. A API key de plataforma não
gerencia endpoints e o header `Organization` não é aceito neste recurso.

## Parâmetros de caminho

<ParamField path="id" type="string" required>
  ID do endpoint (`we_*`).
</ParamField>

## Attributes

<ParamField body="events" type="array">
  Substitui a lista de tipos assinados. Pelo menos um, todos do
  [catálogo público](/api-reference/events/types). Wildcards não são
  aceitos; envie cada tipo explicitamente.
</ParamField>

<ParamField body="name" type="string">
  Nome interno. Envie `null` ou `""` para limpar.
</ParamField>

<ParamField body="url" type="string">
  Nova URL de entrega. Em produção precisa ser `https`.
</ParamField>

<RequestExample>
  ```bash cURL theme={"theme":"css-variables"}
  curl -X POST "https://api.chargefy.io/v1/webhook-endpoints/we_FqaSfAzqzmGrfWLU" \
    -H "Authorization: Bearer {{API_KEY}}" \
    -H "Content-Type: application/json" \
    -d '{
      "events": ["charge.refunded", "payment.intent.succeeded", "refund.created"]
    }'
  ```
</RequestExample>

## Resposta

`200 OK` com o objeto [`webhook_endpoint`](/api-reference/webhook-endpoints/object)
completo atualizado, sem o `secret` e sem diff — quem precisa do diff lê o
webhook correspondente.

<ResponseExample>
  ```json 200 theme={"theme":"css-variables"}
  {
    "id": "we_FqaSfAzqzmGrfWLU",
    "object": "webhook_endpoint",
    "created_at": "2026-07-19T12:00:00Z",
    "events": [
      "charge.refunded",
      "payment.intent.succeeded",
      "refund.created"
    ],
    "events_from": "organization",
    "livemode": true,
    "metadata": {},
    "name": "Servidor principal",
    "updated_at": "2026-07-19T13:00:00Z",
    "url": "https://meusite.com/webhooks/chargefy"
  }
  ```

  ```json 400 theme={"theme":"css-variables"}
  {
    "error": {
      "code": "invalid_request",
      "message": "events_from is immutable after creation. Create a separate endpoint for the other stream.",
      "param": "events_from",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={"theme":"css-variables"}
  {
    "error": {
      "code": "authentication_failed",
      "message": "Unauthorized — invalid api key",
      "type": "authentication_error"
    }
  }
  ```

  ```json 404 theme={"theme":"css-variables"}
  {
    "error": {
      "code": "resource_missing",
      "message": "Webhook endpoint not found",
      "type": "invalid_request_error"
    }
  }
  ```
</ResponseExample>

## Erros

| Status | Quando                                                                                                                                                                                         |
| ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | Tentativa de mudar `events_from`; `url` inválida ou `http` em produção; `events` vazio ou com tipo fora do catálogo; `secret` enviado no payload; `metadata` preenchido (ainda não suportado). |
| `401`  | Credencial ausente, inválida, revogada ou expirada.                                                                                                                                            |
| `403`  | API key sem escopo `write`, ou API key de plataforma (não gerencia endpoints).                                                                                                                 |
| `404`  | Endpoint não existe nesta organização ou neste ambiente, ou já foi removido.                                                                                                                   |

<CardGroup cols={2}>
  <Card title="Objeto Webhook Endpoint" icon="cube" href="/api-reference/webhook-endpoints/object">
    Campos, fluxo de eventos e comportamento do secret.
  </Card>

  <Card title="Tipos de eventos" icon="bell" href="/api-reference/events/types">
    Catálogo exato aceito no array `events`.
  </Card>
</CardGroup>
