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

# Atualizar Webhook da Loja (PATCH)

> Atualiza a lista de eventos inscritos para um webhook já cadastrado na loja.

## 🔄 Atualizar Webhook da Loja

Este endpoint permite atualizar os eventos inscritos (`events`) de um webhook já cadastrado na loja, utilizando `PATCH` ou `PUT` com a mesma estrutura de corpo.

### 🔐 Autenticação

Esta rota exige autenticação via API Key, enviada no header da requisição:

```http theme={null}
Authorization: SUA_API_KEY_AQUI
```

### 📥 Parâmetros de Rota

| Parâmetro | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `storeId` | `string (UUID)` | Sim | ID da loja |

### 📦 Corpo da Requisição

| Campo | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `url` | `string (URI)` | Sim | URL do webhook já cadastrado (`http://` ou `https://`, entre `9` e `200` caracteres). |
| `events` | `string[]` | Sim | Lista de eventos desejados (mínimo de 1 item; eventos válidos suportados pela API). |

### 📋 Exemplo de Requisição

```bash theme={null}
curl --location --request PATCH "https://api.cabrapi.com.br/v1/stores/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/webhooks" \
--header "Authorization: SUA_API_KEY_AQUI" \
--header "Content-Type: application/json" \
--data '{
  "url": "https://meusistema.com/callback",
  "events": [
    "payment.status.changed",
    "payment.updated"
  ]
}'
```

> Também é possível usar `PUT` na mesma rota (`/v1/stores/{storeId}/webhooks`) com o mesmo corpo.

### 📊 Exemplo de Resposta (200)

```json theme={null}
{
  "code": "WEBHOOK_UPDATED",
  "webhook": "https://meusistema.com/callback",
  "events": [
    "payment.status.changed",
    "payment.updated"
  ]
}
```

### ❌ Possíveis Erros

| Status | Code | Quando acontece |
| - | - | - |
| `400` | `STORE_ID_REQUIRED` | Código morto: a rota exige `storeId`; nunca dispara na prática. |
| `400` | `INVALID_URL` | Quando a `url` não é informada ou não é uma URL HTTP/HTTPS válida (`9` a `200` caracteres). |
| `400` | `INVALID_DATA` | Quando `events` é omitido, enviado vazio (`[]`) ou contém algum evento não suportado. |
| `401` | `API_KEY_NOT_PROVIDED` | Header `Authorization` não enviado. |
| `401` | `INVALID_API_KEY` | API Key inválida ou não encontrada. |
| `403` | `USER_DISABLED` | Conta do usuário desativada ou excluída. |
| `403` | `NO_ACTIVE_SUBSCRIPTION` | Conta sem plano ativo. |
| `404` | `STORE_NOT_FOUND` | Quando a loja não existe ou não está acessível. |
| `404` | `WEBHOOK_NOT_FOUND` | Quando a `url` informada não está cadastrada nesta loja. |
| `429` | `RATE_LIMIT_EXCEEDED` | Limite de requisições por minuto do plano excedido. |
| `500` | `WEBHOOK_ERROR` | Falha interna ao salvar os eventos do webhook. |
| `503` | `SERVICE_UNAVAILABLE` | Serviço temporariamente indisponível. |


## OpenAPI

````yaml PATCH /stores/{storeId}/webhooks
openapi: 3.1.0
info:
  title: caBRAPI
  version: 1.0.0
servers:
  - url: https://api.cabrapi.com.br/v1
security: []
paths:
  /stores/{storeId}/webhooks:
    patch:
      tags:
        - Webhooks
      summary: Update webhook events
      operationId: patchWebhook
      parameters:
        - $ref: '#/components/parameters/StoreId'
      requestBody:
        content:
          application/json:
            schema:
              properties:
                events:
                  items:
                    enum:
                      - store.created
                      - store.updated
                      - store.deleted
                      - store.reordered
                      - product.created
                      - product.updated
                      - product.deleted
                      - product.reordered
                      - category.created
                      - category.updated
                      - category.deleted
                      - category.reordered
                      - coupon.created
                      - coupon.updated
                      - coupon.deleted
                      - coupon.reordered
                      - page.upserted
                      - page.deleted
                      - affiliate.created
                      - affiliate.updated
                      - affiliate.deleted
                      - payment.created
                      - payment.updated
                      - payment.deleted
                      - payment.status.changed
                    type: string
                  minItems: 1
                  type: array
                url:
                  format: uri
                  maxLength: 200
                  minLength: 9
                  type: string
              required:
                - url
                - events
              type: object
        description: Webhook URL and updated event subscriptions.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    example: WEBHOOK_UPDATED
                    type: string
                  events:
                    items:
                      enum:
                        - store.created
                        - store.updated
                        - store.deleted
                        - store.reordered
                        - product.created
                        - product.updated
                        - product.deleted
                        - product.reordered
                        - category.created
                        - category.updated
                        - category.deleted
                        - category.reordered
                        - coupon.created
                        - coupon.updated
                        - coupon.deleted
                        - coupon.reordered
                        - page.upserted
                        - page.deleted
                        - affiliate.created
                        - affiliate.updated
                        - affiliate.deleted
                        - payment.created
                        - payment.updated
                        - payment.deleted
                        - payment.status.changed
                      type: string
                    type: array
                  webhook:
                    format: uri
                    type: string
                required:
                  - code
                  - webhook
                  - events
                type: object
          description: Webhook updated.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Invalid request.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Missing or invalid API key.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Forbidden (inactive plan or insufficient permissions).
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Resource not found.
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Rate limit exceeded.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal server error.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Service unavailable.
      security:
        - ApiKey: []
components:
  parameters:
    StoreId:
      in: path
      name: storeId
      required: true
      schema:
        type: string
        minLength: 1
        maxLength: 50
  schemas:
    Error:
      properties:
        code:
          example: STORE_NOT_FOUND
          type: string
      required:
        - code
      type: object
  securitySchemes:
    ApiKey:
      in: header
      name: Authorization
      type: apiKey
      x-default: YOUR_API_KEY_HERE

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.