> ## 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.

# Add Webhook to Store

> Adds a new webhook to the store, respecting the plan limit.

## ➕ Add Webhook to Store

This endpoint allows adding a new webhook URL to the store, respecting the maximum limit allowed by the plan.

### 🔐 Authentication

This route requires authentication via API Key, sent in the request header:

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

### 📥 Route Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| `storeId` | `string (UUID)` | Yes | Store ID |

### 📥 Request Body

| Field | Type | Required | Description |
| - | - | - | - |
| `url` | `string` | Yes | Webhook endpoint URL (valid URI, minimum 9 and maximum 200 characters) |
| `events` | `string[]` | No | List of events subscribed by the webhook. If omitted or empty, subscribes to all available events. |

### 📋 Request Example

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

### 📊 Response Example (200)

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

> **Update events (`PUT` / `PATCH`):** You can also send `PUT` or `PATCH /v1/stores/{storeId}/webhooks` with `{ "url": "...", "events": [...] }` (at least 1 valid event required) to update the events of an existing webhook; on success, returns `200` with `code: "WEBHOOK_UPDATED"`, `"webhook"`, and `"events"` (or `404 WEBHOOK_NOT_FOUND` if the URL is not registered).

### ❌ Possible Errors

| Status | Code | When it happens |
| - | - | - |
| `400` | `STORE_ID_REQUIRED` | Dead code: the route requires `storeId`; never fires in practice. |
| `400` | `INVALID_URL` | Invalid body or missing URL/outside the standard. |
| `400` | `INVALID_DATA` | One or more events provided in `events` are invalid. |
| `400` | `OWNER_API_KEY_MISSING` | Store owner has no API Key registered for test encryption. |
| `400` | `WEBHOOK_INVALID` | Webhook URL responded with an HTTP error status in the webhook test (if the URL is inaccessible/invalid by network, returns `500 WEBHOOK_ERROR`). |
| `400` | `WEBHOOK_ALREADY_EXISTS` | Webhook URL already registered for the store. |
| `400` | `WEBHOOK_LIMIT_REACHED` | Webhook limit reached for the store's plan (includes the `"max"` field in the response JSON). |
| `401` | `API_KEY_NOT_PROVIDED` | `Authorization` header not sent. |
| `401` | `INVALID_API_KEY` | Invalid or not found API Key. |
| `403` | `USER_DISABLED` | User account disabled or deleted. |
| `403` | `NO_ACTIVE_SUBSCRIPTION` | Account has no active plan. |
| `404` | `STORE_NOT_FOUND` | Store does not exist or does not belong to your account. |
| `429` | `RATE_LIMIT_EXCEEDED` | Plan per-minute request limit exceeded. |
| `500` | `WEBHOOK_ERROR` | Internal failure while processing the request. |
| `503` | `SERVICE_UNAVAILABLE` | Service temporarily unavailable. |


## OpenAPI

````yaml POST /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:
    post:
      tags:
        - Webhooks
      summary: Add webhook to store
      operationId: createWebhook
      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
                  type: array
                url:
                  format: uri
                  maxLength: 200
                  minLength: 9
                  type: string
              required:
                - url
              type: object
        description: Webhook URL and optional event subscriptions.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    example: WEBHOOK_ADDED
                    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 added.
        '400':
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    example: WEBHOOK_LIMIT_REACHED
                    type: string
                  max:
                    example: 2
                    type: integer
                required:
                  - code
          description: >-
            Invalid request (e.g. INVALID_URL, INVALID_DATA,
            OWNER_API_KEY_MISSING, WEBHOOK_INVALID, WEBHOOK_ALREADY_EXISTS,
            WEBHOOK_LIMIT_REACHED).
        '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.