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

# Actualizar webhook

> Modifica el nombre, URL o eventos de un webhook existente. Todos los campos son opcionales.

Puedes enviar solo los campos que quieres actualizar; los demás se mantienen sin cambios.

### Path Parameters

<ParamField path="id" type="string" required>
  ID del webhook a actualizar.
</ParamField>

### Body

<ParamField body="name" type="string">
  Nuevo nombre descriptivo del webhook (máx. 255 caracteres).
</ParamField>

<ParamField body="description" type="string">
  Nueva descripción del webhook (máx. 500 caracteres). Envía `null` para borrarla.
</ParamField>

<ParamField body="url" type="string">
  Nueva URL HTTPS de destino. Debe ser una URL válida.
</ParamField>

<ParamField body="events" type="array">
  Nueva lista completa de eventos. Reemplaza los eventos existentes. Debe contener al menos un evento si se envía.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl https://api.onepay.la/v1/webhooks/a1b2c3d4-e5f6-7890-abcd-ef1234567890 \
    -X PUT \
    -H "Authorization: Bearer sk_test_xxx" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Webhook actualizado",
      "events": [
        "payment.approved",
        "charge.paid",
        "cashout.completed",
        "cashout.rejected"
      ]
    }'
  ```

  ```javascript JavaScript theme={null}
  const id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';

  const response = await fetch(`https://api.onepay.la/v1/webhooks/${id}`, {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer sk_test_xxx',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'Webhook actualizado',
      events: [
        'payment.approved',
        'charge.paid',
        'cashout.completed',
        'cashout.rejected'
      ]
    })
  });

  const webhook = await response.json();
  ```

  ```python Python theme={null}
  import requests

  webhook_id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890'

  response = requests.put(
      f'https://api.onepay.la/v1/webhooks/{webhook_id}',
      headers={
          'Authorization': 'Bearer sk_test_xxx',
          'Content-Type': 'application/json'
      },
      json={
          'name': 'Webhook actualizado',
          'events': [
              'payment.approved',
              'charge.paid',
              'cashout.completed',
              'cashout.rejected'
          ]
      }
  )

  webhook = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $id = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
  $curl = curl_init();

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.onepay.la/v1/webhooks/{$id}",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer sk_test_xxx",
      "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode([
      "name" => "Webhook actualizado",
      "events" => [
        "payment.approved",
        "charge.paid",
        "cashout.completed",
        "cashout.rejected"
      ]
    ])
  ]);

  $response = curl_exec($curl);
  $webhook = json_decode($response, true);
  ?>
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "data": {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "name": "Webhook actualizado",
      "description": "Notificaciones de pagos y dispersiones",
      "url": "https://mi-servidor.com/webhooks/onepay",
      "events": [
        "payment.approved",
        "charge.paid",
        "cashout.completed",
        "cashout.rejected"
      ],
      "header": null,
      "is_test": false,
      "created_at": "2025-01-20T14:30:00+00:00",
      "updated_at": "2025-01-20T16:45:00+00:00"
    }
  }
  ```

  ```json 422 theme={null}
  {
    "message": "El campo events debe ser un arreglo.",
    "code": 10001,
    "code_name": "validation_error",
    "errors": {
      "events": ["El campo events debe ser un arreglo."]
    }
  }
  ```

  ```json 404 theme={null}
  {
    "message": "Webhook no encontrado.",
    "code": 10004,
    "code_name": "not_found"
  }
  ```
</ResponseExample>
