# Webhooks

> Receive on your server every invoice stamped, rejected or cancelled, with signed events retried for 3 days.

A webhook is an address on your server where Fiscalisto sends an event every time a document in your account changes. With them your system learns what doesn't happen in a request's answer: a cancellation the customer accepts days later, an invoice the PAC took a while to stamp or a batch that finished.

## Event types

These are all there are. Each one carries in `data.object` the whole object, the same as its `GET`, with the state it had when it happened. Open one to see the whole event as it arrives, field by field.

| Event | When it arrives | `data.object` |
| --- | --- | --- |
| [`invoice.stamped`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-stamped) | A CFDI was stamped: invoice, payment complement, credit note, advance, its application note, replacement or payroll receipt. It also arrives when one that stayed `processing` (the PAC didn't answer) is stamped later. | Invoice (`inv_…`), `status: "valid"` |
| [`invoice.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-failed) | SAT or the PAC rejected a CFDI. It arrives even if the request already answered `422`, and when one in `processing` ends rejected. | Invoice, `status: "rejected"`, with `error` |
| [`invoice.cancellation_pending`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-cancellation-pending) | You asked for the cancellation and it isn't done yet: the customer must accept it in their buzón tributario (see [when](https://fiscalisto.com/en/docs/api/cancelacion#when-the-customer-must-accept-it)), SAT is finishing it, or Fiscalisto asks again on its own because SAT doesn't accept it yet (see [when](https://fiscalisto.com/en/docs/api/cancelacion#when-fiscalisto-asks-again)). It stays valid meanwhile. | Invoice, `cancellation.status: "pending"` (with `status: "pending"`) or `"scheduled"` |
| [`invoice.canceled`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-canceled) | It was cancelled: right away, or because the customer accepted or didn't answer in 3 business days. | Invoice, `status: "canceled"`, `cancellation.status: "accepted"` |
| [`invoice.cancellation_rejected`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-cancellation-rejected) | The customer rejected the cancellation, or SAT never got the request. It stays valid; you can ask again. | Invoice, `status: "valid"`, `cancellation.status: "rejected"` or `"lapsed"` |
| [`invoice.cancellation_failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-cancellation-failed) | Fiscalisto stopped requesting a cancellation SAT didn't accept. It stays valid; request it again. | Invoice, `status: "valid"`, `cancellation.status: "failed"`, with `cancellation.error` |
| [`invoice.partially_paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-partially-paid) | A payment for part of a PPD invoice arrived: a payment complement or a credit note. See [Accounts receivable](https://fiscalisto.com/en/docs/api/cuentas-por-cobrar). | Invoice, with what's left in `amount_due` |
| [`invoice.paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-paid) | An income invoice no longer owes anything: its last complement, a credit note, a reconciled deposit or `mark_paid`. | Invoice, with `payment_status: paid` |
| [`invoice.email_bounced`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-email-bounced) | An invoice's email didn't reach an address: the mailbox doesn't exist, is full or the domain doesn't take email. Once per address and send. | Invoice, with the address and the reason in `email.recipients` |
| [`invoice.email_complained`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-email-complained) | The customer marked an invoice's email as spam. | Invoice, with `email.status: "complained"` |
| [`retention.stamped`](https://fiscalisto.com/en/docs/api/referencia/eventos/retention-stamped) | A withholding certificate was stamped. | Certificate (`ret_…`), `status: "valid"` |
| [`retention.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/retention-failed) | SAT or the PAC rejected a certificate. | Certificate, `status: "rejected"` |
| [`retention.canceled`](https://fiscalisto.com/en/docs/api/referencia/eventos/retention-canceled) | A certificate was cancelled (they need no acceptance). | Certificate, `status: "canceled"` |
| [`invoice_batch.completed`](https://fiscalisto.com/en/docs/api/referencia/eventos/invoice-batch-completed) | No invoice of the batch is left to stamp: each was stamped or failed. Each invoice of the batch also sends its `invoice.stamped` or `invoice.failed`. | Batch (`bat_…`), `status: "completed"` |
| [`payroll_batch.completed`](https://fiscalisto.com/en/docs/api/referencia/eventos/payroll-batch-completed) | No receipt of the [payroll batch](https://fiscalisto.com/en/docs/api/nomina#stamp-the-whole-payroll-at-once) is left to stamp. It carries each employee's receipt: the stamped ones, with their invoice, and the rest, with their error. Each receipt also sends its `invoice.stamped` or `invoice.failed`. | Payroll batch (`pyb_…`), with `receipts` |
| [`issuer.ready`](https://fiscalisto.com/en/docs/api/referencia/eventos/issuer-ready) | A live issuer can stamp now: it has its CSD and signed the contract with the PAC. In test, when an [onboarding link](https://fiscalisto.com/en/docs/api/emisores#let-your-customer-upload-their-files) is finished. | Issuer (`iss_…`), `status: "active"` |
| [`customer_data_request.completed`](https://fiscalisto.com/en/docs/api/referencia/eventos/customer-data-request-completed) | A customer sent their tax data with a [link](https://fiscalisto.com/en/docs/api/datos-del-cliente#ask-the-customer-for-their-data). | Request (`cdr_…`), `status: "completed"` |
| [`sat_download.completed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-download-completed) | A [SAT download](https://fiscalisto.com/en/docs/api/descargas-del-sat) finished: its invoices are in `GET /v1/sat_invoices`. | Download (`sdl_…`), `status: "completed"` |
| [`sat_download.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-download-failed) | SAT couldn't finish a download; the reason comes in `error`. | Download (`sdl_…`), `status: "failed"` |
| [`sat_declaration.created`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-declaration-created) | A [tax return lookup](https://fiscalisto.com/en/docs/api/declaraciones-del-sat) found a new one. Its files and figures may arrive later. | Tax return (`dcl_…`) |
| [`sat_declaration.updated`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-declaration-updated) | A return's PDF, receipt, financial statements or figures arrived. | Tax return (`dcl_…`), as it stands |
| [`sat_refresh.completed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-refresh-completed) | A SAT query (returns, opinion, certificate or mailbox) finished and its timbre was used. | SAT query (`srf_…`), with what it brought in `result` |
| [`sat_refresh.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sat-refresh-failed) | SAT didn't answer a query; its timbre came back. | SAT query (`srf_…`), with the reason in `error` |
| [`ticket.invoiced`](https://fiscalisto.com/en/docs/api/referencia/eventos/ticket-invoiced) | Your buyer invoiced a ticket on the [self-invoicing](https://fiscalisto.com/en/docs/api/autofactura) portal. Its invoice's `invoice.stamped` arrives too. | Ticket (`tkt_…`), `status: "invoiced"`, with the invoice in `invoice` |
| [`recurring_invoice.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/recurring-invoice-failed) | A [recurring invoice](https://fiscalisto.com/en/docs/api/facturas-recurrentes) couldn't stamp its period (no timbres, the customer deleted, SAT rejected it). It arrives once; it's tried again each day. | Recurring invoice (`rin_…`), with the reason in `last_error` |
| [`quote.viewed`](https://fiscalisto.com/en/docs/api/referencia/eventos/quote-viewed) | The customer opened a [quote](https://fiscalisto.com/en/docs/api/cotizaciones)'s link for the first time. | Quote (`quo_…`) |
| [`quote.accepted`](https://fiscalisto.com/en/docs/api/referencia/eventos/quote-accepted) | A quote was accepted: by the customer on its link or by you with `POST /v1/quotes/{id}/accept`. | Quote, with `decided_by` |
| [`quote.changes_requested`](https://fiscalisto.com/en/docs/api/referencia/eventos/quote-changes-requested) | The customer asked for changes on the link. At most once every 10 minutes. | Quote, with what they wrote in `customer_comment` |
| [`quote.rejected`](https://fiscalisto.com/en/docs/api/referencia/eventos/quote-rejected) | The quote was rejected: by the customer on its link or by you with `POST /v1/quotes/{id}/reject`. | Quote, with `decided_by` and the reason in `customer_comment` |
| [`quote.withdrawn`](https://fiscalisto.com/en/docs/api/referencia/eventos/quote-withdrawn) | You withdrew the quote: its link no longer lets it be accepted. | Quote, `status: "withdrawn"` |
| [`sales_order.confirmed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sales-order-confirmed) | An order was confirmed: it can be delivered and invoiced now. | Order, `status: "confirmed"` |
| [`sales_order.customer_confirmed`](https://fiscalisto.com/en/docs/api/referencia/eventos/sales-order-customer-confirmed) | Your customer confirmed the order on its link. | Order, with `customer_confirmed_at` |
| [`sales_order.delivered`](https://fiscalisto.com/en/docs/api/referencia/eventos/sales-order-delivered) | Everything in the order went out. | Order, with `delivered_at` |
| [`sales_order.paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/sales-order-paid) | The order's invoices were paid. | Order, `status: "paid"` |
| [`sales_order.canceled`](https://fiscalisto.com/en/docs/api/referencia/eventos/sales-order-canceled) | An order was cancelled. | Order, `status: "canceled"` |
| [`supplier_invoice.received`](https://fiscalisto.com/en/docs/api/referencia/eventos/supplier-invoice-received) | A supplier sent an invoice through the [supplier portal](https://fiscalisto.com/en/docs/api/portal-de-proveedores). | Supplier invoice (`spi_…`), `status: "received"` |
| [`supplier_invoice.approved`](https://fiscalisto.com/en/docs/api/referencia/eventos/supplier-invoice-approved) | A supplier invoice was approved, at all its levels: it can go to your ERP now. | Supplier invoice, `status: "approved"` |
| [`supplier_invoice.rejected`](https://fiscalisto.com/en/docs/api/referencia/eventos/supplier-invoice-rejected) | A supplier invoice was rejected. | Supplier invoice, with `rejection_reason` |
| [`supplier_invoice.scheduled`](https://fiscalisto.com/en/docs/api/referencia/eventos/supplier-invoice-scheduled) | A supplier invoice's payment date was scheduled or changed. | Supplier invoice, with `scheduled_on` |
| [`supplier_invoice.paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/supplier-invoice-paid) | A supplier invoice was marked paid. | Supplier invoice, `status: "paid"` |
| [`portal_supplier.approved`](https://fiscalisto.com/en/docs/api/referencia/eventos/portal-supplier-approved) | A portal supplier's registration was approved: it can send invoices now. | Portal supplier (`sup_…`), `status: "approved"` |
| [`payout.approved`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-approved) | A supplier pago has all its signatures: it goes out on its date. | Pago (`pyo_…`), `status: "approved"` |
| [`payout.paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-paid) | Every transfer of a pago arrived. | Pago, `status: "paid"` |
| [`payout.partially_paid`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-partially-paid) | A pago ended with transfers that didn't arrive. | Pago, `status: "partially_paid"` |
| [`payout.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-failed) | No transfer of a pago arrived. | Pago, `status: "failed"` |
| [`payout.canceled`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-canceled) | A pago was canceled before going out. | Pago, with `cancel_reason` |
| [`payout_transfer.succeeded`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-transfer-succeeded) | A transfer to a supplier arrived. | Transfer (`pyt_…`), with `tracking_key` |
| [`payout_transfer.failed`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-transfer-failed) | A transfer to a supplier didn't go out. | Transfer, with `failure_reason` |
| [`payout_transfer.returned`](https://fiscalisto.com/en/docs/api/referencia/eventos/payout-transfer-returned) | The supplier's bank returned a transfer. | Transfer, with `failure_reason` |
| [`ticket.included_in_global`](https://fiscalisto.com/en/docs/api/referencia/eventos/ticket-included-in-global) | A ticket nobody invoiced went into the period's global invoice. | Ticket (`tkt_…`), `status: "global"`, with the global invoice in `global_invoice` |
| [`balance.low`](https://fiscalisto.com/en/docs/api/referencia/eventos/balance-low) | The account has few live timbres left: when it drops to `low_balance_at` and again when they run out, once each until it has more again. See [What a timbre costs](https://fiscalisto.com/en/docs/api/pruebas-y-produccion#what-a-timbre-costs). | Balance (`object: "balance"`), like `GET /v1/balance`; always `livemode: true` |
| [`usage.high`](https://fiscalisto.com/en/docs/api/referencia/eventos/usage-high) | The API used 80 % of its live requests of the last 30 days, and again at 100 % (once each per month). See [Requests per month](https://fiscalisto.com/en/docs/api/limites#requests-per-month). | Usage (`object: "usage"`); always `livemode: true` |
| [`test_clock.ready`](https://fiscalisto.com/en/docs/api/referencia/eventos/test-clock-ready) | A [test clock](https://fiscalisto.com/en/docs/api/pruebas-y-produccion#move-time-forward-with-a-test-clock) finished moving forward: each day's work is done. Test only. | Test clock (`object: "test_clock"`) |
| [`rule.matched`](https://fiscalisto.com/en/docs/api/referencia/eventos/rule-matched) | A [rule](https://fiscalisto.com/en/docs/api/reglas) with the `webhook` action matched. It only reaches that rule's webhook, even if others listen to every event. | Which rule, the record and every field of its conditions (`object: "rule_match"`); always `livemode: true` |

What sends no event: creating or changing customers, products, issuers and webhooks (your system does that and already has the answer), and email sends.

```json title="invoice.stamped"
{
  "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", "status": "valid", "...": "..." }
  }
}
```

| Field | What it is |
| --- | --- |
| `id` | The event's id. It's the same in the `webhook-id` header and on every retry: use it to avoid processing it twice. |
| `type` | One of the events in the table. |
| `api_version` | The API version the object was built with. |
| `livemode` | `false` if it comes from test (`fk_test_`), `true` from live. |
| `created_at` | When it happened, Mexico City time. |
| `data.object` | The whole object. |

Each event's page (in the table above) has a complete example of what it sends, and [`GET /v1/events`](https://fiscalisto.com/en/docs/api/referencia/eventos/list-events) returns those of the last 30 days.

## Adding a webhook

Each `url` goes in a single endpoint per mode, so no event arrives twice: creating another with the same one answers `400` `endpoint_exists` with the id of the one that has it, to change it with `POST /v1/webhook_endpoints/{id}`.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/webhook_endpoints \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://mi-plataforma.mx/webhooks/fiscalisto",
    "events": ["invoice.stamped", "invoice.failed", "invoice.canceled"]
  }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const webhookEndpoint = await fiscalisto.webhookEndpoints.create({
  url: "https://mi-plataforma.mx/webhooks/fiscalisto",
  events: [
    "invoice.stamped",
    "invoice.failed",
    "invoice.canceled",
  ],
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

webhook_endpoint = fiscalisto.webhook_endpoints.create({
    "url": "https://mi-plataforma.mx/webhooks/fiscalisto",
    "events": [
        "invoice.stamped",
        "invoice.failed",
        "invoice.canceled",
    ],
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$webhookEndpoint = $fiscalisto->webhookEndpoints->create([
    'url' => 'https://mi-plataforma.mx/webhooks/fiscalisto',
    'events' => [
        'invoice.stamped',
        'invoice.failed',
        'invoice.canceled',
    ],
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	webhookEndpoint, err := client.WebhookEndpoints.Create(ctx, &fiscalisto.CreateWebhookEndpointParams{
		URL: "https://mi-plataforma.mx/webhooks/fiscalisto",
		Events: []string{
			"invoice.stamped",
			"invoice.failed",
			"invoice.canceled",
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(webhookEndpoint.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateWebhookEndpointParams;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookEndpoint = fiscalisto.webhookEndpoints().create(new CreateWebhookEndpointParams()
        .setUrl("https://mi-plataforma.mx/webhooks/fiscalisto")
        .setEvents(List.of(
                "invoice.stamped",
                "invoice.failed",
                "invoice.canceled"
        )));
System.out.println(webhookEndpoint.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookEndpoint = await fiscalisto.WebhookEndpoints.CreateAsync(new CreateWebhookEndpointParams
{
    Url = "https://mi-plataforma.mx/webhooks/fiscalisto",
    Events = new()
    {
        "invoice.stamped",
        "invoice.failed",
        "invoice.canceled",
    },
});
```

The answer carries the `secret` (`whsec_…`) once: keep it on your server. Without `events` it receives all of them. You can also add it in **Desarrolladores › Webhooks**. Each mode has its own webhooks: one created with an `fk_test_` key only receives test events.

The address must be `https` and public. Redirects aren't followed: use the final address. To test on your computer you don't need a tunnel: `npx fiscalisto listen --forward-to http://localhost:3000/webhooks/fiscalisto` forwards your test account's events to you signed just like the real ones, and `npx fiscalisto trigger invoice.stamped` triggers one (see [CLI](https://fiscalisto.com/en/docs/api/cli#webhooks-on-your-computer)). If you'd rather register a real endpoint, open a tunnel (`cloudflared tunnel --url http://localhost:3000` or `ngrok http 3000`) and register the `https` address it gives you.

## Verifying the signature

Every event arrives as a `POST` with three headers, per [Standard Webhooks](https://www.standardwebhooks.com):

| Header | What it is |
| --- | --- |
| `webhook-id` | The event's id (`evt_…`). It's the same on every retry. |
| `webhook-timestamp` | When this try was sent, in seconds since 1970. |
| `webhook-signature` | `v1,` and the HMAC-SHA256 signature in base64. It may carry several separated by spaces. |

Always verify the signature before trusting the event: anyone can send a `POST` to your address. With the [SDKs](https://fiscalisto.com/en/docs/api/sdk#webhooks) it's one line and doesn't need the API key: `verifyWebhook(body, headers, secret)` in TypeScript, `verify_webhook(…)` in Python, `Webhook::verify(…)` in PHP, `fiscalisto.VerifyWebhook(…)` in Go, `Webhooks.verify(…)` in Java and `FiscalistoClient.Webhooks.Verify(…)` in C#. In another language, the `standardwebhooks` library does the same (Ruby, Rust and the rest).

```ts title="Node.js (Express) with the SDK"
import express from "express";
import { verifyWebhook } from "fiscalisto";

const app = express();

// El cuerpo tal como llegó, sin convertirlo a JSON: la firma es de esos bytes.
app.post("/webhooks/fiscalisto", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    event = await verifyWebhook(req.body, req.headers, process.env.FISCALISTO_WEBHOOK_SECRET);
  } catch {
    return res.status(400).send("Firma inválida");
  }
  res.sendStatus(200); // Responda rápido; procese después.
  procesar(event);
});
```

```python title="Python (Flask) with the SDK"
import os
from flask import Flask, request
from fiscalisto import FiscalistoWebhookError, verify_webhook

app = Flask(__name__)

@app.post("/webhooks/fiscalisto")
def fiscalisto():
    try:
        event = verify_webhook(
            request.get_data(), request.headers, os.environ["FISCALISTO_WEBHOOK_SECRET"]
        )
    except FiscalistoWebhookError:
        return "Firma inválida", 400
    procesar(event)
    return "", 200
```

### Without a library

The signature is the HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}` with your secret without the `whsec_` prefix, decoded from base64:

```python title="verificar.py"
import base64, hashlib, hmac, json, time

def verificar(secreto, headers, cuerpo: bytes):
    msg_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]
    if abs(time.time() - int(timestamp)) > 300:
        raise ValueError("Evento viejo: puede ser una repetición maliciosa")
    llave = base64.b64decode(secreto.removeprefix("whsec_"))
    firmado = f"{msg_id}.{timestamp}.".encode() + cuerpo
    esperada = base64.b64encode(hmac.new(llave, firmado, hashlib.sha256).digest()).decode()
    for firma in headers["webhook-signature"].split(" "):
        version, _, valor = firma.partition(",")
        if version == "v1" and hmac.compare_digest(valor, esperada):
            return json.loads(cuerpo)
    raise ValueError("Firma inválida")
```

Reject events more than 5 minutes off in `webhook-timestamp`: that way nobody can replay an old one.

## Testing your webhooks

With an `fk_test_` key everything happens in test and your test webhooks receive real events:

1. Add a test webhook with your tunnel's address (see above).
2. Stamp an invoice with your test key: with `curl`, with an SDK or with **Probar** in the [reference](https://fiscalisto.com/en/docs/api/referencia/facturas/create-invoice). `invoice.stamped` arrives.
3. For `invoice.failed`, stamp to one of the [test RFCs](https://fiscalisto.com/en/docs/api/pruebas-y-produccion#trigger-each-sat-rejection), like `NOM010101FK9`; for `invoice.canceled`, cancel the invoice with `"motive": "02"`.
4. In **Desarrolladores › Webhooks** see each delivery with what your server answered, and resend it as many times as you like while you fix your code. **Desarrolladores › Eventos** has every event, with what was sent and each delivery.

### A test event, without stamping

To test your code with any event, send a test one to your webhook. It arrives right away, once, signed like real ones, with a sample object (its ids don't exist), even if the webhook doesn't listen to that type:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/webhook_endpoints/whe_8Kq2ZtR4mNw1Lp0sXc7V/test \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "invoice.failed" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const webhookTest = await fiscalisto.webhookEndpoints.test("whe_8Kq2ZtR4mNw1Lp0sXc7V", { type: "invoice.failed" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

webhook_test = fiscalisto.webhook_endpoints.test("whe_8Kq2ZtR4mNw1Lp0sXc7V", {"type": "invoice.failed"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$webhookTest = $fiscalisto->webhookEndpoints->test('whe_8Kq2ZtR4mNw1Lp0sXc7V', ['type' => 'invoice.failed']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	webhookTest, err := client.WebhookEndpoints.Test(ctx, "whe_8Kq2ZtR4mNw1Lp0sXc7V", &fiscalisto.TestWebhookEndpointParams{
		Type: fiscalisto.String("invoice.failed"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *webhookTest)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.TestWebhookEndpointParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookTest = fiscalisto.webhookEndpoints().test("whe_8Kq2ZtR4mNw1Lp0sXc7V", new TestWebhookEndpointParams().setType("invoice.failed"));
System.out.println(webhookTest);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookTest = await fiscalisto.WebhookEndpoints.TestAsync("whe_8Kq2ZtR4mNw1Lp0sXc7V", new TestWebhookEndpointParams { Type = "invoice.failed" });
```

The answer carries the event that was sent and what your server answered:

```json
{
  "object": "webhook_test",
  "event": { "id": "evt_0PKhIdhYuAGwzmMQYfkc", "object": "event", "type": "invoice.failed", "...": "..." },
  "delivery": { "ok": true, "status": 200, "error": null, "response_body": "{\"received\":true}", "duration_ms": 182 }
}
```

Without `type` it sends `invoice.stamped`. In the dashboard it's **Mandar evento de prueba**, on each webhook. The test event doesn't show in `GET /v1/events`, but it does in the webhook's deliveries, and you can resend it.

## Responding

- Answer a `2xx` status in under 15 seconds. Any other status, a redirect or not answering in time counts as a failure.
- Answer first and process later (in a queue or in the background), so you don't go over 15 seconds.
- An event may arrive more than once. Keep the `webhook-id` of those you already processed and ignore repeats.
- Events may arrive out of order. To know a document's current state use the `status` of the object the event carries or look it up with `GET`.

## Retries

If your server fails, we retry the same event for about 3 days: after 5 seconds, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours and 10 hours, then every 12 hours four more times, so a server down over a weekend loses no events. Each try carries the same `webhook-id` and a new `webhook-timestamp`.

A webhook that fails every retry goes to `status: "failing"`. If it stays like that 5 days, it's turned off (`"disabled"`) and stops receiving events; turn it back on with [`POST /v1/webhook_endpoints/{id}`](https://fiscalisto.com/en/docs/api/referencia/webhooks/update-webhook-endpoint) and `"disabled": false`, or in the dashboard. If your server answers `410 Gone`, we take it that the address no longer exists: the webhook is turned off right then (`disabled_reason: "gone"`), without waiting 5 days. In **Desarrolladores › Webhooks** each webhook shows its last 7 days (delivered, failed, error rate and average response) and its deliveries with what your server answered, and you can resend any. **Reenviar** (resend) is a separate try, now: it doesn't change the automatic retries, and if it arrives, there are no more retries.

When a production webhook has received nothing for a few hours, we email the account's owners and admins, with the address and what your server answered; and again if it's turned off. Test webhooks send no email.

If you missed events, [`GET /v1/events`](https://fiscalisto.com/en/docs/api/referencia/eventos/list-events) has those of the last 30 days; filter by `type` (one, or all of a resource's with a wildcard: `invoice.*`), by `object` (the document's id) or with `delivery_success=false` for those some webhook didn't receive:

```bash tab="cURL"
curl "https://api.fiscalisto.com/v1/events?type=invoice.*&delivery_success=false" \
  -H "Authorization: Bearer $FISCALISTO_API_KEY"
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

for await (const item of fiscalisto.events.list({ type: "invoice.*", delivery_success: false })) {
  console.log(item.id);
}
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

for item in fiscalisto.events.list({"type": "invoice.*", "delivery_success": False}):
    print(item["id"])
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

foreach ($fiscalisto->events->list([
    'type' => 'invoice.*',
    'delivery_success' => false,
]) as $item) {
    echo $item['id'], "\n";
}
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	for item, err := range client.Events.ListAutoPaging(ctx, &fiscalisto.ListEventsParams{
		Type:            fiscalisto.String("invoice.*"),
		DeliverySuccess: fiscalisto.Bool(false),
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.ID)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ListEventsParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

for (var item : fiscalisto.events().listAutoPaging(new ListEventsParams().setType("invoice.*").setDeliverySuccess(false))) {
    System.out.println(item.getId());
}
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

await foreach (var item in fiscalisto.Events.ListAutoPagingAsync(new ListEventsParams
{
    Type = "invoice.*",
    DeliverySuccess = false,
}))
    Console.WriteLine(item.Id);
```

Once your server answers, send each one again with [`POST /v1/events/{id}/resend`](https://fiscalisto.com/en/docs/api/referencia/eventos/resend-event). With `endpoint` it goes only to that webhook; without it, to all the enabled ones that listen to that event type. It's the dashboard's same **Reenviar**: a separate try, now, with the same `webhook-id`, so your server recognizes it if it already processed it.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/events/evt_0PKhIdhYuAGwzmMQYfkc/resend \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "endpoint": "whe_8Kq2ZtR4mNw1Lp0sXc7V" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const eventResend = await fiscalisto.events.resend("evt_0PKhIdhYuAGwzmMQYfkc", { endpoint: "whe_8Kq2ZtR4mNw1Lp0sXc7V" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

event_resend = fiscalisto.events.resend("evt_0PKhIdhYuAGwzmMQYfkc", {"endpoint": "whe_8Kq2ZtR4mNw1Lp0sXc7V"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$eventResend = $fiscalisto->events->resend('evt_0PKhIdhYuAGwzmMQYfkc', ['endpoint' => 'whe_8Kq2ZtR4mNw1Lp0sXc7V']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	eventResend, err := client.Events.Resend(ctx, "evt_0PKhIdhYuAGwzmMQYfkc", &fiscalisto.ResendEventParams{
		Endpoint: fiscalisto.String("whe_8Kq2ZtR4mNw1Lp0sXc7V"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *eventResend)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ResendEventParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var eventResend = fiscalisto.events().resend("evt_0PKhIdhYuAGwzmMQYfkc", new ResendEventParams().setEndpoint("whe_8Kq2ZtR4mNw1Lp0sXc7V"));
System.out.println(eventResend);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var eventResend = await fiscalisto.Events.ResendAsync("evt_0PKhIdhYuAGwzmMQYfkc", new ResendEventParams
{
    Endpoint = "whe_8Kq2ZtR4mNw1Lp0sXc7V",
});
```

### Seeing a webhook's deliveries

[`GET /v1/webhook_endpoints/{id}/deliveries`](https://fiscalisto.com/en/docs/api/referencia/webhooks/list-webhook-deliveries) tells you what happened with each event on that webhook, most recent first: whether it arrived (`succeeded`), what your server answered (`status`, `error`, `duration_ms`), how many tries it has had (`attempts`) and when the next retry goes (`next_retry_at`). It's the same **Entregas** list as the dashboard. With `succeeded=false` you see only those your server didn't receive:

```bash tab="cURL"
curl -G https://api.fiscalisto.com/v1/webhook_endpoints/whe_8Kq2ZtR4mNw1Lp0sXc7V/deliveries \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -d succeeded=false
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

for await (const item of fiscalisto.webhookEndpoints.listDeliveries("whe_8Kq2ZtR4mNw1Lp0sXc7V", { succeeded: false })) {
  console.log(item.id);
}
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

for item in fiscalisto.webhook_endpoints.list_deliveries("whe_8Kq2ZtR4mNw1Lp0sXc7V", {"succeeded": False}):
    print(item["id"])
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

foreach ($fiscalisto->webhookEndpoints->listDeliveries('whe_8Kq2ZtR4mNw1Lp0sXc7V', ['succeeded' => false]) as $item) {
    echo $item['id'], "\n";
}
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	for item, err := range client.WebhookEndpoints.ListDeliveriesAutoPaging(ctx, "whe_8Kq2ZtR4mNw1Lp0sXc7V", &fiscalisto.ListWebhookDeliveriesParams{
		Succeeded: fiscalisto.Bool(false),
	}) {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(item.ID)
	}
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.ListWebhookDeliveriesParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

for (var item : fiscalisto.webhookEndpoints().listDeliveriesAutoPaging("whe_8Kq2ZtR4mNw1Lp0sXc7V", new ListWebhookDeliveriesParams().setSucceeded(false))) {
    System.out.println(item.getId());
}
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

await foreach (var item in fiscalisto.WebhookEndpoints.ListDeliveriesAutoPagingAsync("whe_8Kq2ZtR4mNw1Lp0sXc7V", new ListWebhookDeliveriesParams { Succeeded = false }))
    Console.WriteLine(item.Id);
```

Each row is an event with its last try; for the next page send the `id` (`whd_…`) of the last one in `starting_after`.

### Recovering everything that didn't arrive

After your server was down, [`POST /v1/webhook_endpoints/{id}/recover`](https://fiscalisto.com/en/docs/api/referencia/webhooks/recover-webhook-endpoint) sends again, now, every event since `since` that the webhook listens to and didn't receive: those whose tries all failed and those that happened while it was turned off. They go out oldest first, up to 1,000 per call; if more are left, `next_since` says where to call again from. Each one carries its usual `webhook-id`, so your server can drop the ones it already had. `since` must be within the last 30 days (what we keep), and the webhook must be turned on. In the dashboard it's **Reenviar fallidas** (resend failed), on each webhook.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/webhook_endpoints/whe_8Kq2ZtR4mNw1Lp0sXc7V/recover \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "since": "2026-11-20T09:00:00-06:00" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const webhookRecovery = await fiscalisto.webhookEndpoints.recover("whe_8Kq2ZtR4mNw1Lp0sXc7V", { since: "2026-11-20T09:00:00-06:00" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

webhook_recovery = fiscalisto.webhook_endpoints.recover("whe_8Kq2ZtR4mNw1Lp0sXc7V", {"since": "2026-11-20T09:00:00-06:00"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$webhookRecovery = $fiscalisto->webhookEndpoints->recover('whe_8Kq2ZtR4mNw1Lp0sXc7V', ['since' => '2026-11-20T09:00:00-06:00']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	webhookRecovery, err := client.WebhookEndpoints.Recover(ctx, "whe_8Kq2ZtR4mNw1Lp0sXc7V", &fiscalisto.RecoverWebhookEndpointParams{
		Since: "2026-11-20T09:00:00-06:00",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *webhookRecovery)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.RecoverWebhookEndpointParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookRecovery = fiscalisto.webhookEndpoints().recover("whe_8Kq2ZtR4mNw1Lp0sXc7V", new RecoverWebhookEndpointParams()
        .setSince("2026-11-20T09:00:00-06:00"));
System.out.println(webhookRecovery);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookRecovery = await fiscalisto.WebhookEndpoints.RecoverAsync("whe_8Kq2ZtR4mNw1Lp0sXc7V", new RecoverWebhookEndpointParams
{
    Since = "2026-11-20T09:00:00-06:00",
});
```

## Rolling the secret

[`POST /v1/webhook_endpoints/{id}/roll_secret`](https://fiscalisto.com/en/docs/api/referencia/webhooks/roll-webhook-secret) gives you a new secret. The old one keeps signing for 24 hours: meanwhile each event carries two signatures, one with each secret, and verification passes with either. Switch your server to the new one within that time. For another term send `previous_secret_expires_in` in seconds; if the secret leaked, send `0` and the old one stops signing right then.

```bash tab="cURL"
curl -X POST https://api.fiscalisto.com/v1/webhook_endpoints/whe_0q1Vmmw52sbDpmtsKD1E/roll_secret \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "previous_secret_expires_in": 0 }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const webhookEndpoint = await fiscalisto.webhookEndpoints.rollSecret("whe_0q1Vmmw52sbDpmtsKD1E", { previous_secret_expires_in: 0 });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

webhook_endpoint = fiscalisto.webhook_endpoints.roll_secret("whe_0q1Vmmw52sbDpmtsKD1E", {"previous_secret_expires_in": 0})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$webhookEndpoint = $fiscalisto->webhookEndpoints->rollSecret('whe_0q1Vmmw52sbDpmtsKD1E', ['previous_secret_expires_in' => 0]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	webhookEndpoint, err := client.WebhookEndpoints.RollSecret(ctx, "whe_0q1Vmmw52sbDpmtsKD1E", &fiscalisto.RollWebhookSecretParams{
		PreviousSecretExpiresIn: fiscalisto.Int64(0),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(webhookEndpoint.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.RollWebhookSecretParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookEndpoint = fiscalisto.webhookEndpoints().rollSecret("whe_0q1Vmmw52sbDpmtsKD1E", new RollWebhookSecretParams().setPreviousSecretExpiresIn(0));
System.out.println(webhookEndpoint.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var webhookEndpoint = await fiscalisto.WebhookEndpoints.RollSecretAsync("whe_0q1Vmmw52sbDpmtsKD1E", new RollWebhookSecretParams { PreviousSecretExpiresIn = 0 });
```
