# Webhooks

Direcciones de su servidor que reciben los eventos, firmados.

La guía, paso a paso: https://fiscalisto.com/docs/api/webhooks.md

## Endpoints

- [Crear un webhook](https://fiscalisto.com/docs/api/referencia/webhooks/create-webhook-endpoint.md): `POST /v1/webhook_endpoints`
- [Listar webhooks](https://fiscalisto.com/docs/api/referencia/webhooks/list-webhook-endpoints.md): `GET /v1/webhook_endpoints`
- [Ver un webhook](https://fiscalisto.com/docs/api/referencia/webhooks/get-webhook-endpoint.md): `GET /v1/webhook_endpoints/{id}`
- [Actualizar un webhook](https://fiscalisto.com/docs/api/referencia/webhooks/update-webhook-endpoint.md): `POST /v1/webhook_endpoints/{id}`
- [Borrar un webhook](https://fiscalisto.com/docs/api/referencia/webhooks/delete-webhook-endpoint.md): `DELETE /v1/webhook_endpoints/{id}`
- [Cambiar el secreto](https://fiscalisto.com/docs/api/referencia/webhooks/roll-webhook-secret.md): `POST /v1/webhook_endpoints/{id}/roll_secret`
- [Mandar un evento de prueba](https://fiscalisto.com/docs/api/referencia/webhooks/test-webhook-endpoint.md): `POST /v1/webhook_endpoints/{id}/test`
- [Listar entregas](https://fiscalisto.com/docs/api/referencia/webhooks/list-webhook-deliveries.md): `GET /v1/webhook_endpoints/{id}/deliveries`
- [Recuperar eventos fallidos](https://fiscalisto.com/docs/api/referencia/webhooks/recover-webhook-endpoint.md): `POST /v1/webhook_endpoints/{id}/recover`

## El objeto WebhookEndpoint

Una dirección de su servidor que recibe eventos.

| Campo | Tipo | Siempre viene | Descripción |
| --- | --- | --- | --- |
| `id` | string | sí | Identificador del objeto, con su prefijo (iss_, inv_, ret_, cus_, prd_, emp_, bat_, brn_, whs_, stm_, adj_, evt_, whe_). |
| `livemode` | boolean | sí | true en producción (llaves fk_live_), false en pruebas (fk_test_). Lo de pruebas no vale ante el SAT. |
| `object` | `"webhook_endpoint"` | sí | Qué tipo de objeto es («invoice», «customer»…). |
| `sandbox` | string o null | sí | El entorno de prueba (sbx_…) al que pertenece, o null si es de la cuenta. Vea /v1/sandboxes. |
| `url` | string | sí | Dirección https de su servidor que recibe los avisos. |
| `description` | string o null | sí | Para qué es, para usted. |
| `events` | arreglo de string | sí | Eventos que quiere recibir, o ["*"] para todos (por omisión). La lista con cuándo llega cada uno: [Tipos de evento](https://fiscalisto.com/docs/api/webhooks#tipos-de-evento). |
| `status` | `enabled`, `failing`, `disabled` | sí | enabled: entregando. failing: sus entregas fallan (se apaga tras 5 días así). disabled: apagado. |
| `disabled_reason` | string o null |  | Por qué se apagó: failing (sus entregas fallaron 5 días seguidos), gone (su servidor contestó 410 Gone) o manual (usted lo apagó). |
| `failing_since` | string (date-time) o null |  | Desde cuándo fallan las entregas, o null. |
| `previous_secret_expires_at` | string (date-time) o null | sí | Hasta cuándo el secreto anterior también firma (después de cambiarlo), o null. |
| `api_version` | string o null | sí | La versión de la API de sus eventos; null: la de la cuenta. |
| `created_at` | string (date-time) o null | sí | Cuándo se creó, ISO 8601 con la hora de la Ciudad de México (-06:00). |
| `secret` | string |  | Secreto de firma (whsec_…). Solo viene al crearlo o al cambiarlo: guárdelo para verificar las firmas. |

Ejemplo:

```json
{
  "id": "whe_0q1Vmmw52sbDpmtsKD1E",
  "object": "webhook_endpoint",
  "livemode": false,
  "sandbox": null,
  "url": "https://mi-plataforma.mx/webhooks/fiscalisto",
  "description": null,
  "events": [
    "invoice.stamped"
  ],
  "status": "enabled",
  "disabled_reason": null,
  "failing_since": null,
  "previous_secret_expires_at": null,
  "api_version": null,
  "created_at": "2026-10-24T10:15:42-06:00",
  "secret": "whsec_MfKQ9r7Cq1ZzR0nN3xY2bW8eT5uV6sA4"
}
```

## El objeto WebhookTest

Un evento de prueba que se mandó a su webhook, y lo que respondió su servidor.

| Campo | Tipo | Siempre viene | Descripción |
| --- | --- | --- | --- |
| `object` | `"webhook_test"` | sí | Qué tipo de objeto es («invoice», «customer»…). |
| `event` | objeto | sí | Algo que pasó en su cuenta: el objeto completo como quedó. Se manda a sus webhooks firmado (Standard Webhooks). |
| `event.id` | string | sí | Identificador del objeto, con su prefijo (iss_, inv_, ret_, cus_, prd_, emp_, bat_, brn_, whs_, stm_, adj_, evt_, whe_). |
| `event.object` | `"event"` | sí | Qué tipo de objeto es («invoice», «customer»…). |
| `event.type` | string | sí | Qué pasó: invoice.stamped, invoice.failed, invoice.canceled, invoice.cancellation_pending, invoice.cancellation_rejected, invoice.cancellation_failed, invoice.paid, invoice.partially_paid, retention.stamped, retention.failed, retention.canceled, invoice_batch.completed, payroll_batch.completed, customer_data_request.completed, sat_download.completed, sat_download.failed, sat_declaration.created, sat_declaration.updated, sat_refresh.completed, sat_refresh.failed, ticket.invoiced, ticket.included_in_global, recurring_invoice.failed, quote.viewed, quote.accepted, quote.changes_requested, quote.rejected, quote.withdrawn, sales_order.confirmed, sales_order.customer_confirmed, sales_order.delivered, sales_order.paid, sales_order.canceled, supplier_invoice.received, supplier_invoice.approved, supplier_invoice.rejected, supplier_invoice.scheduled, supplier_invoice.paid, portal_supplier.approved, payout.approved, payout.paid, payout.partially_paid, payout.failed, payout.canceled, payout_transfer.succeeded, payout_transfer.failed, payout_transfer.returned, issuer.ready, balance.low, usage.high, test_clock.ready o rule.matched. |
| `event.api_version` | string | sí | Versión de la API con que se armó el objeto. |
| `event.livemode` | boolean | sí | true en producción (llaves fk_live_), false en pruebas (fk_test_). Lo de pruebas no vale ante el SAT. |
| `event.created_at` | string (date-time) | sí | Cuándo se creó, ISO 8601 con la hora de la Ciudad de México (-06:00). |
| `event.data` | objeto | sí | Lo que cambió, en data.object: el comprobante (o el lote) completo, como lo contesta su GET. |
| `event.data.object` | objeto | sí | El objeto como quedó: una factura, una constancia o un lote. |
| `delivery` | objeto | sí | Cómo le fue: ok si contestó 2xx, el código, el error y el inicio de su respuesta. |
| `delivery.ok` | boolean | sí | true si su servidor contestó 2xx. |
| `delivery.status` | integer o null | sí | El código HTTP que contestó; null si no se pudo conectar. |
| `delivery.error` | string o null | sí | Qué falló (sin respuesta, no se pudo conectar, otro código), o null. |
| `delivery.response_body` | string o null | sí | El inicio de lo que contestó su servidor (hasta 2,000 caracteres). |
| `delivery.duration_ms` | integer | sí | Cuánto tardó su servidor, en milisegundos. (de -9007199254740991 a 9007199254740991) |

Ejemplo:

```json
{
  "object": "webhook_test",
  "event": {
    "id": "evt_0PKhIdhYuAGwzmMQYfkc",
    "object": "event",
    "type": "invoice.stamped",
    "api_version": "2026-10-24",
    "livemode": false,
    "created_at": "2026-10-24T10:15:42-06:00",
    "data": {
      "object": {
        "id": "inv_OufpKqnrvx9p28SINJVjjWKYRhojBTJb8P",
        "object": "invoice",
        "livemode": false,
        "issuer": "iss_OufpKqnrvx9p",
        "branch": null,
        "cost_center": null,
        "type": "I",
        "status": "valid",
        "uuid": "5F1E8C2A-3B7D-4C9E-A1B2-C3D4E5F60718",
        "series": null,
        "folio": "1",
        "date": "2026-10-24T10:15:42",
        "customer": {
          "tax_id": "ICV060329BY0",
          "legal_name": "INMOBILIARIA CVA",
          "tax_system": "601",
          "zip": "33826"
        },
        "use": "G03",
        "payment_form": "03",
        "payment_method": "PUE",
        "currency": "MXN",
        "exchange_rate": null,
        "items": [
          {
            "description": "Consultoría",
            "product_key": "80101500",
            "unit_key": "E48",
            "unit_name": "Unidad de servicio",
            "quantity": 1,
            "unit_price": 1000,
            "taxability": "02",
            "iva": "0.16"
          }
        ],
        "subtotal": 1000,
        "discount": 0,
        "taxes": {
          "iva": 160,
          "ieps": 0,
          "iva_withheld": 0,
          "isr_withheld": 0,
          "local_transferred": 0,
          "local_withheld": 0
        },
        "total": 1160,
        "payment_status": "paid",
        "amount_due": 0,
        "amount_paid": 1160,
        "related": null,
        "cancellation": null,
        "email": null,
        "error": null,
        "recurring_invoice": null,
        "tickets": [],
        "origin": {
          "type": "api",
          "name": "Tienda en línea"
        },
        "created_at": "2026-10-24T10:15:42-06:00",
        "metadata": {}
      }
    }
  },
  "delivery": {
    "ok": true,
    "status": 200,
    "error": null,
    "response_body": "{\"received\":true}",
    "duration_ms": 182
  }
}
```

## El objeto WebhookDelivery

Lo que pasó con un evento en un webhook: su último intento, cuántos lleva y cuándo va el siguiente.

| Campo | Tipo | Siempre viene | Descripción |
| --- | --- | --- | --- |
| `object` | `"webhook_delivery"` | sí | Qué tipo de objeto es («invoice», «customer»…). |
| `id` | string | sí | El último intento (whd_…). Úselo en starting_after para la página siguiente. |
| `webhook_endpoint` | string | sí | El webhook (whe_…). |
| `event` | string | sí | El evento (evt_…). Reenvíelo con POST /v1/events/{id}/resend. |
| `event_type` | string o null | sí | El tipo del evento (invoice.stamped…). |
| `succeeded` | boolean | sí | true si su servidor contestó 2xx en el último intento. |
| `status` | integer o null | sí | El código HTTP que contestó su servidor; null si no se pudo conectar. |
| `error` | string o null | sí | Qué falló (tiempo de espera, DNS, o el inicio de su respuesta); null si llegó. |
| `duration_ms` | integer | sí | Cuánto tardó su servidor en contestar el último intento. (de -9007199254740991 a 9007199254740991) |
| `attempts` | integer | sí | Cuántas veces se ha mandado a este webhook, reenvíos incluidos. (de -9007199254740991 a 9007199254740991) |
| `resent` | boolean | sí | true si el último intento fue un reenvío (POST /v1/events/{id}/resend). |
| `test` | boolean | sí | true si es un evento de prueba (POST /v1/webhook_endpoints/{id}/test); no se reintenta. |
| `created_at` | string (date-time) | sí | Cuándo fue el último intento. |
| `next_retry_at` | string (date-time) o null | sí | Cuándo va el siguiente reintento automático; null si llegó o ya no hay más. |

Ejemplo:

```json
{
  "object": "webhook_delivery",
  "id": "whd_48213",
  "webhook_endpoint": "whe_0q1Vmmw52sbDpmtsKD1E",
  "event": "evt_0PKhIdhYuAGwzmMQYfkc",
  "event_type": "invoice.stamped",
  "succeeded": false,
  "status": 503,
  "error": "Respondió 503.",
  "duration_ms": 1840,
  "attempts": 3,
  "resent": false,
  "test": false,
  "created_at": "2026-11-14T10:40:12-06:00",
  "next_retry_at": "2026-11-14T12:40:12-06:00"
}
```

## El objeto WebhookRecovery

Los eventos que un webhook no recibió, mandados otra vez: desde cuándo se buscaron, cuántos salieron y, si quedaron más de 1,000, desde dónde seguir.

| Campo | Tipo | Siempre viene | Descripción |
| --- | --- | --- | --- |
| `object` | `"webhook_recovery"` | sí | Qué tipo de objeto es («invoice», «customer»…). |
| `endpoint` | string | sí | El webhook (whe_…) al que se mandaron. |
| `since` | string | sí | Desde cuándo se buscaron: el since que mandó, o la creación del webhook si es posterior. |
| `events` | integer | sí | Cuántos eventos salieron otra vez. 0: no le faltaba ninguno. (de -9007199254740991 a 9007199254740991) |
| `next_since` | string o null | sí | Si quedaron más de 1,000: llame otra vez con este since. null: ya salieron todos. |

Ejemplo:

```json
{
  "object": "webhook_recovery",
  "endpoint": "whe_8Kq2ZtR4mNw1Lp0sXc7V",
  "since": "2026-11-20T09:00:00-06:00",
  "events": 42,
  "next_since": null
}
```
