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

# Actualizar webhook

> Actualiza la configuración de un webhook existente

export const EnterpriseText = ({lang = 'pt'}) => ({
  pt: <>Este endpoint requer a role <strong>ENTERPRISE</strong> na sua conta.</>,
  en: <>This endpoint requires the <strong>ENTERPRISE</strong> role on your account.</>,
  es: <>Este endpoint requiere el rol <strong>ENTERPRISE</strong> en tu cuenta.</>
})[lang];

## Conceptos

Actualiza parcialmente la configuración de un webhook. Solo se actualizan los campos que envías en el body; el resto se mantiene sin cambios.

### Actualizar los eventos

Al enviar el campo `events`, la lista sustituye **todos** los eventos existentes:

```json theme={null}
{ "events": ["MESSAGE_RECEIVED", "MESSAGE_STATUS", "CONNECTED"] }
```

### Habilitar o rotar la firma HMAC

Si envías `signing: true`, se genera un `secret` nuevo y se devuelve en esa respuesta. Úsalo también para **rotar** el secret sin necesidad de recrear el webhook.

```json theme={null}
{ "signing": true }
```

<Warning>
  El nuevo `secret` se devuelve **solo en esa respuesta**. Guárdalo antes de salir de la página o de cerrar la sesión.
</Warning>

### Deshabilitar temporalmente

```json theme={null}
{ "status": "DISABLED" }
```

Mientras esté `DISABLED`, el webhook deja de recibir eventos. Para reactivarlo:

```json theme={null}
{ "status": "ENABLED" }
```

<Note>
  <EnterpriseText lang="es" />
</Note>

<Note>
  El `webhookId` se obtiene en la respuesta del endpoint [Crear webhook](/es/webhooks/create-webhook) o [Listar webhooks](/es/webhooks/list-webhooks).
</Note>


## OpenAPI

````yaml es/webhooks/openapi.json PATCH /v1/channels/{channelId}/webhooks/{webhookId}
openapi: 3.1.0
info:
  title: Omni Z-API - API de webhooks
  description: >-
    API para crear y gestionar endpoints de webhook por canal. Requiere el rol
    ENTERPRISE.
  version: 1.0.0
servers:
  - url: https://api.omni.z-api.io
security:
  - bearerAuth: []
paths:
  /v1/channels/{channelId}/webhooks/{webhookId}:
    patch:
      tags:
        - Webhooks
      summary: Actualizar webhook
      description: >-
        Actualiza parcialmente la configuración del webhook. Solo se actualizan
        los campos que se envían.
      operationId: updateWebhook
      parameters:
        - name: channelId
          in: path
          required: true
          description: ID del canal
          schema:
            type: string
            example: 019E4C54B1B375A28970B605CA9B03C3
        - name: webhookId
          in: path
          required: true
          description: ID del webhook
          schema:
            type: string
            example: A1B2C3D4E5F6789012345678901234AB
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateWebhookRequest'
            examples:
              disable:
                summary: Deshabilitar webhook
                value:
                  status: DISABLED
              reenable:
                summary: Volver a habilitar el webhook
                value:
                  status: ENABLED
              updateUrlAndEvents:
                summary: Actualizar la URL y los eventos
                value:
                  url: https://nova-url.suempresa.com/webhooks/omni-zapi
                  events:
                    - MESSAGE_RECEIVED
                    - MESSAGE_STATUS
                    - CONNECTED
                    - DISCONNECTED
              enableSignature:
                summary: Habilitar / rotar la firma HMAC
                value:
                  signing: true
              updateAuth:
                summary: Cambiar la autenticación a Bearer
                value:
                  auth:
                    type: BEARER
                    token: novo-token-secreto
      responses:
        '200':
          description: >-
            Webhook actualizado correctamente. El campo `secret` se devuelve
            **solo** cuando se ha habilitado `signing` en esta actualización.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookCreatedResponse'
              examples:
                afterEnableSigning:
                  summary: Después de habilitar la firma (se devuelve el secret)
                  value:
                    id: A1B2C3D4E5F6789012345678901234AB
                    channelId: 019E4C54B1B375A28970B605CA9B03C3
                    instanceId: 019E4C54B1B375A28970B605CA9B03C3
                    url: https://app.suempresa.com/webhooks/omni-zapi
                    description: Webhook principal de producción
                    events:
                      - MESSAGE_RECEIVED
                      - MESSAGE_STATUS
                    status: ENABLED
                    signing: true
                    secret: >-
                      d4e5f6789012345678901234abcdef0123456789abcdef0123456789ab12c3d4
                    auth:
                      type: BEARER
                      configured: true
                    payloadFormat: DEFAULT
                    customAttributes: {}
                    createdAt: 2025-01-15T10:30:00.000+0000
                    updatedAt: 2025-01-20T14:00:00.000+0000
                afterDisable:
                  summary: Después de deshabilitarla (sin secret)
                  value:
                    id: A1B2C3D4E5F6789012345678901234AB
                    channelId: 019E4C54B1B375A28970B605CA9B03C3
                    instanceId: 019E4C54B1B375A28970B605CA9B03C3
                    url: https://app.suempresa.com/webhooks/omni-zapi
                    description: Webhook principal de producción
                    events:
                      - MESSAGE_RECEIVED
                      - MESSAGE_STATUS
                    status: DISABLED
                    signing: true
                    auth:
                      type: BEARER
                      configured: true
                    payloadFormat: DEFAULT
                    customAttributes: {}
                    createdAt: 2025-01-15T10:30:00.000+0000
                    updatedAt: 2025-01-20T15:00:00.000+0000
        '400':
          description: Petición no válida
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: 400
                message: Validation error
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          description: Webhook no encontrado
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: 404
                message: Webhook not found
        '422':
          description: 'Regla de negocio incumplida: cuenta sin el rol ENTERPRISE'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: 422
                message: This action requires ENTERPRISE role
components:
  schemas:
    UpdateWebhookRequest:
      type: object
      description: >-
        Todos los campos son opcionales: solo se actualizan los campos que se
        envían.
      properties:
        url:
          type: string
          description: Nueva URL de destino
          example: https://nova-url.suempresa.com/webhooks/omni-zapi
        description:
          type: string
          description: Nueva descripción
        events:
          type: array
          description: 'Nueva lista de eventos: sustituye todos los eventos existentes'
          items:
            type: string
            enum:
              - MESSAGE_RECEIVED
              - MESSAGE_DELIVERY
              - MESSAGE_STATUS
              - RECEIVED_STATUS
              - RECEIVED_AND_DELIVERY
              - CONNECTED
              - DISCONNECTED
              - PRESENCE_CHAT
              - INITIAL_DATA
              - BLOCK
        status:
          type: string
          enum:
            - ENABLED
            - DISABLED
          description: '`DISABLED` pausa la entrega de eventos sin eliminar el webhook'
        signing:
          type: boolean
          description: >-
            Habilita o rota la firma HMAC. Genera un `secret` nuevo que se
            devuelve en la respuesta.
        auth:
          $ref: '#/components/schemas/WebhookAuth'
        payloadFormat:
          type: string
          enum:
            - DEFAULT
            - Z_API
            - CHATWOOT
        customAttributes:
          type: object
          additionalProperties: true
    WebhookCreatedResponse:
      allOf:
        - $ref: '#/components/schemas/WebhookResponse'
        - type: object
          properties:
            secret:
              type: string
              description: >-
                Secret HMAC de 64 caracteres hexadecimales: se devuelve **solo**
                cuando se habilita `signing` en el create o el update. Guárdalo
                de forma segura; después no se podrá recuperar.
              example: a3f1c2d4e5b6789012345678901234abcdef0123456789abcdef0123456789ab
    Error:
      type: object
      properties:
        error:
          type: integer
        message:
          type: string
    WebhookAuth:
      type: object
      description: Configura cómo se autentica Omni Z-API al llamar a tu URL
      properties:
        type:
          type: string
          enum:
            - NONE
            - BEARER
            - API_KEY
            - BASIC
            - CUSTOM_HEADER
          description: Tipo de autenticación
          example: BEARER
        token:
          type: string
          description: >-
            Token para la autenticación `BEARER`: se envía en el header
            `Authorization: Bearer <token>`
          example: mi-token-secreto
        key:
          type: string
          description: Clave para la autenticación `API_KEY`
        username:
          type: string
          description: Usuario para la autenticación `BASIC`
        password:
          type: string
          description: Contraseña para la autenticación `BASIC`
        headerName:
          type: string
          description: Nombre del header para `CUSTOM_HEADER`
          example: X-Api-Key
        headerValue:
          type: string
          description: Valor del header para `CUSTOM_HEADER`
    WebhookResponse:
      type: object
      properties:
        id:
          type: string
          description: ID único del webhook
          example: A1B2C3D4E5F6789012345678901234AB
        channelId:
          type: string
          description: ID del canal al que pertenece el webhook
          example: 019E4C54B1B375A28970B605CA9B03C3
        instanceId:
          type: string
          deprecated: true
          description: 'Obsoleto: usa `channelId`'
          example: 019E4C54B1B375A28970B605CA9B03C3
        url:
          type: string
          description: URL de destino de los eventos
          example: https://app.suempresa.com/webhooks/omni-zapi
        description:
          type: string
          nullable: true
          description: Descripción del webhook
          example: Webhook principal de producción
        events:
          type: array
          description: Tipos de evento configurados
          items:
            type: string
          example:
            - MESSAGE_RECEIVED
            - MESSAGE_STATUS
        status:
          type: string
          enum:
            - ENABLED
            - DISABLED
          description: Estado actual del webhook
          example: ENABLED
        signing:
          type: boolean
          description: Indica si la firma HMAC está habilitada
          example: true
        auth:
          $ref: '#/components/schemas/WebhookAuthInfo'
        payloadFormat:
          type: string
          enum:
            - DEFAULT
            - Z_API
            - CHATWOOT
          description: Formato del payload entregado
          example: DEFAULT
        customAttributes:
          type: object
          additionalProperties: true
          description: Atributos extra configurados
          example: {}
        createdAt:
          type: string
          format: date-time
          description: Fecha de creación
          example: 2025-01-15T10:30:00.000+0000
        updatedAt:
          type: string
          format: date-time
          description: Fecha de la última actualización
          example: 2025-01-15T10:30:00.000+0000
    WebhookAuthInfo:
      type: object
      description: >-
        Resumen de la autenticación configurada: las credenciales no se
        devuelven por seguridad
      properties:
        type:
          type: string
          enum:
            - NONE
            - BEARER
            - API_KEY
            - BASIC
            - CUSTOM_HEADER
          example: BEARER
        configured:
          type: boolean
          description: '`true` cuando hay credenciales configuradas'
          example: true
  responses:
    Unauthorized:
      description: Token no válido o ausente.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 401
            message: Unauthorized
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Secret Key generada en el panel de Seguridad de Omni Z-API

````