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

> ## Agent Instructions
> Melso MCP: https://mcp.melso.ai/mcp (OAuth; one company per connection). Documentation-search MCP: https://docs.melso.ai/mcp; it does not act on customer accounts. Melso API: https://api.melso.ai/v1, with a company API key or a partner key (early access); invoicing is live and the other operations are marked beta.
>
> Use the live tool list and respect company membership. Ask the person to approve the exact invoice or tax return version in the signed-in app. Melso's professionals prepare and file included returns after approval; an AI assistant does not file. A prepared file or an approval is not evidence of filing: only the AEAT's reference and receipt are. Keep credentials out of chat and logs.

# Webhooks

> Get an event at your endpoint when an incorporation, a company, a certificate, a tax return or a payroll run changes. Signed, retried, replayable.

> [!WARNING]
>
> **Beta.** Melso does not send these events yet, and their fields can still
> change.

Melso sends an event to your endpoint whenever something changes in one of
your firm's companies: an incorporation moves forward, a company has
everything it needs, a certificate is about to expire, a tax return waits for
approval or has been filed.

Use webhooks to react, and [List events](https://docs.melso.ai/api/partner/reference/list-events.md) to
reconcile. Both return the same objects.

## Add an endpoint

Your firm's owner or an admin adds endpoints in the Melso console, under
**Settings** › **Developers** › **Webhooks**, or with
[Create a webhook endpoint](https://docs.melso.ai/api/partner/reference/create-webhook-endpoint.md):

```bash theme={null}
curl https://api.melso.ai/v1/partner/webhook-endpoints \
  -H "Authorization: Bearer $MELSO_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/melso/webhooks",
    "events": ["incorporation.*", "company.ready", "tax_return.*"]
  }'
```

```json theme={null}
{
  "id": "we_3f9a1c2b",
  "url": "https://example.com/melso/webhooks",
  "events": ["incorporation.*", "company.ready", "tax_return.*"],
  "status": "enabled",
  "secret": "whsec_…",
  "created_at": "2026-12-01T09:30:00Z"
}
```

`secret` appears only in this answer. Store it to verify signatures. An
endpoint receives the events of every company of your firm.

## The event object

```json theme={null}
{
  "id": "evt_8b1d4e7a",
  "type": "incorporation.completed",
  "created_at": "2026-12-14T11:02:00Z",
  "company_id": "1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e",
  "data": {
    "object": {
      "id": "7c6b5a4d-3e2f-4a1b-9c8d-7e6f5a4b3c2d",
      "type": "sl",
      "status": "completed",
      "company_id": "1b2c3d4e-5f6a-4b7c-8d9e-0f1a2b3c4d5e"
    }
  }
}
```

| Field | Meaning |
| - | - |
| `id` | Unique per event. The same event can arrive twice: skip an `id` you have already handled. |
| `type` | What happened. See the table below. |
| `company_id` | The company it concerns. `null` for an incorporation that has no company yet. |
| `data.object` | The object as its GET endpoint returns it at the time of the event. |

## Event types

| Type | When |
| - | - |
| `incorporation.updated` | An incorporation changes status. |
| `incorporation.action_required` | Melso's team needs something from the owner: a document, a signature, an appointment. |
| `incorporation.completed` | The business has its NIF. `data.object.company_id` is its new company. |
| `company.ready` | Nothing is missing any more: Melso's professionals can do the company's taxes. |
| `company.missing_changed` | The company's `missing` list changes. |
| `certificate.expiring` | The certificate expires in 30 days. |
| `certificate.expired` | The certificate has expired. Melso cannot file until a new one is uploaded. |
| `tax_return.approval_pending` | A tax return is ready for the company to approve. |
| `tax_return.approved` | The company approved that exact version. |
| `tax_return.filed` | Melso filed it. `data.object` carries the AEAT's reference. |
| `tax_return.rejected` | The AEAT refused it. Melso's professionals are on it. |
| `payroll_run.ready` | A month's payroll is ready for review. |

Subscribe to a whole family with a wildcard, such as `tax_return.*`.

## Verify the signature

Every request carries a `Melso-Signature` header:

```text theme={null}
Melso-Signature: t=1765710120,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
```

`v1` is the HMAC-SHA256 of `t`, a `.` and the raw request body, keyed with the
endpoint's secret. Compare it in constant time, and refuse a `t` older than five
minutes.

```javascript Node.js theme={null}
import crypto from "node:crypto";

export function verify(rawBody, header, secret) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${parts.t}.${rawBody}`)
    .digest("hex");
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
  return fresh && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
```

```python Python theme={null}
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + raw_body, hashlib.sha256).hexdigest()
    fresh = abs(time.time() - int(parts["t"])) < 300
    return fresh and hmac.compare_digest(expected, parts["v1"])
```

Verify against the raw body, before any JSON parsing.

## Respond, retries and order

* Answer `2xx` within 10 seconds, then do the work. Anything else is a failure.
* Melso retries a failed event with exponential backoff for 3 days. An endpoint
  that keeps failing is disabled, and the firm's owner and admins get an email.
* Events can arrive more than once and out of order. Use `id` to skip
  duplicates, and read the current state with the object's GET endpoint when
  order matters.

## Replay and reconcile

[List events](https://docs.melso.ai/api/partner/reference/list-events.md) returns the last 30 days of
events for your firm, newest first. Filter by `type`, `company_id` or
`created_after`. Use it to rebuild what an outage missed, or instead of
webhooks if you prefer polling.

```bash theme={null}
curl "https://api.melso.ai/v1/partner/events?type=tax_return.filed&created_after=2026-12-01T00:00:00Z" \
  -H "Authorization: Bearer $MELSO_PARTNER_KEY"
```

## Test an endpoint

Send a test event from **Settings** › **Developers** › **Webhooks**, or with
[Send a test event](https://docs.melso.ai/api/partner/reference/send-test-event.md). The console lists
each endpoint's recent deliveries, with their status and your response code,
and can resend any of them.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.