Register a partner-level webhook endpoint (events for ALL managed tenants)
const url = 'https://api.emite.cr/v1/partner/webhooks';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"url":"https://example.com/webhooks/emitecr","events":["invoice.submitted","invoice.accepted","invoice.rejected","invoice.error","credentials.rejected","credentials.restored"],"description":"Production ERP integration","environment":"sandbox"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.emite.cr/v1/partner/webhooks \ --header 'Content-Type: application/json' \ --data '{ "url": "https://example.com/webhooks/emitecr", "events": [ "invoice.submitted", "invoice.accepted", "invoice.rejected", "invoice.error", "credentials.rejected", "credentials.restored" ], "description": "Production ERP integration", "environment": "sandbox" }'Answers 201 with the endpoint and its signing secret, which is returned exactly ONCE. Each delivery carries X-Emitecr-Signature: t=<unix seconds>,v1=<hex>: verify it by recomputing v1 = hex HMAC-SHA256(secret, <t>.<raw body>). https-only; private/reserved addresses are rejected at registration AND delivery. Every event carries the tenantId of the company it is about. The endpoint receives the events of ONE environment of every company — required, since a partner key is not bound to one; a production endpoint requires production access (403 PARTNER_PRODUCTION_NOT_ENABLED). To receive both environments, register one endpoint in each: each has its own secret.
Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”Partner app credential (ecp_*)
Request Bodyrequired
Section titled “Request Bodyrequired”object
Where each event is POSTed: https:// only, at most 2000 characters, no credentials in it, and a host that resolves to public addresses only (400 WEBHOOK_URL_INVALID with params.reason). Checked again before every delivery. A delivery succeeds only with a 2xx answer within 10 seconds; redirects are not followed, and anything else is retried with growing delays for up to 72 hours (24 in sandbox), honoring Retry-After on a 429 or a 503. Registering the same URL twice in one environment delivers every event twice, each signed with its own secret.
Example
https://example.com/webhooks/emitecrThe event types this endpoint receives, 1 to 20 (repeats are ignored; an unknown one answers 400 WEBHOOK_EVENT_UNKNOWN with params.events). invoice.submitted: a document was sent to Hacienda and awaits its verdict. invoice.accepted / invoice.rejected: Hacienda's verdict, sent once per document (data.detail carries Hacienda's message) and never for a document imported from another system. invoice.error: the document ended in error instead of a verdict (data.detail carries the error code). credentials.rejected: Hacienda refuses the company's ATV credentials for that environment, and its documents wait, numbered, until they work again. credentials.restored: they work again. A type added to the catalog later never reaches an endpoint registered before.
Example
[ "invoice.submitted", "invoice.accepted", "invoice.rejected", "invoice.error", "credentials.rejected", "credentials.restored"]Free text to tell the endpoints apart, at most 200 characters. Returned as is when listing them.
Example
Production ERP integrationThe environment whose events it receives, sandbox or production — never both, and it cannot be changed later. Required: a partner key is not bound to an environment. A production endpoint requires the partner app to have production access (403 PARTNER_PRODUCTION_NOT_ENABLED). To receive both environments, register one endpoint in each.
Example
productionResponses
Section titled “Responses”object
Identifier of the endpoint — what unregistering it takes: DELETE /v1/webhooks/:id, or DELETE /v1/partner/webhooks/:webhookId for a partner's endpoint.
The environment whose events it receives — sandbox or production, never both — fixed at registration: every event it is sent carries this environment. To receive both, register one endpoint in each, each with its own secret.
The https:// URL each event is POSTed to, as registered.
The event types the endpoint receives, without repeats. They are fixed at registration: to change them, register a new endpoint. A type added to the catalog later never reaches an endpoint registered before it.
The free text given at registration to tell the endpoints apart; null when none was given.
active: it receives the events it subscribed to. paused: its last attempts all failed, so its deliveries wait (heldDeliveries) and one of them probes it now and then (nextProbeAt); the first success resumes it — a probe, a redelivery, or a test. disabled: it stayed paused for days without a success and receives nothing (see disabledReason) until a test of it succeeds, which reactivates it.
Delivery attempts that failed in a row since the last successful one, retries included and across all event types; back to 0 after a success. At 10 the endpoint is paused.
When the current streak of failed attempts began; null while the last attempt succeeded. A paused endpoint whose streak is 7 days old is disabled.
When a delivery to it last succeeded; null when none has yet.
When a delivery attempt to it last failed; null when none has.
When the current pause began; null unless status is paused.
When a paused endpoint is probed next, with the delivery that has waited longest: 5 minutes after the pause, then half of how long it has been paused, at most an hour apart (later if it answered with Retry-After). null unless status is paused.
Deliveries waiting for this endpoint while it is paused. They go out, oldest first, as soon as it answers again; one whose window ends first (72 hours from its first attempt, 24 in sandbox) is recorded as expired.
When it was disabled; null unless status is disabled.
Why it was disabled: auto_failures — it stayed paused for 7 days without a single successful delivery. null unless status is disabled.
After a secret rotation, until when the previous secret still signs each delivery next to the new one (a second v1 in X-Emitecr-Signature); null when only one secret signs. The secret cannot be rotated again until then.
When it was registered.
The signing secret of this endpoint (it starts with whsec_). Verify each delivery by recomputing the v1 of X-Emitecr-Signature: t=<unix seconds>,v1=<hex> = hex HMAC-SHA256(secret, <t>.<raw body>). Returned only in this response: it is stored encrypted and cannot be retrieved later — losing it means rotating it.
Example
{ "environment": "sandbox", "url": "https://example.com/webhooks/emitecr", "events": [ "invoice.accepted", "invoice.rejected" ], "description": "Production ERP integration", "status": "active", "consecutiveFailures": 0, "heldDeliveries": 0, "disabledReason": "auto_failures"}