Webhooks
Webhooks
Webhook endpoint management for receiving real-time event notifications. Configure URLs, select events, and monitor delivery status.
Event types
Subscribe to any combination of these events:
| Category | Events |
|---|---|
| Invoices | invoice.created invoice.updated invoice.sent invoice.paid invoice.overdue invoice.voided |
| Customers | customer.created customer.updated customer.deleted |
| Payments | payment.received payment.failed |
| Items | item.created item.updated item.deleted item.restored |
| Estimates | estimate.created estimate.sent estimate.accepted estimate.rejected |
| Credit notes | credit_note.created credit_note.updated credit_note.voided |
| Advance invoices | advance_invoice.created advance_invoice.updated advance_invoice.paid advance_invoice.applied advance_invoice.voided |
| Document emails | email.delivered email.bounced email.complained email.opened (Amazon SES delivery events for sent documents; opens only when the entity enabled open tracking) |
Subscribing to groups
Instead of listing every event, events also accepts patterns:
*- every event<resource>.*- every event of one resource, e.g.invoice.*,credit_note.*,e_invoicing.submission.*document.*- every event of invoices, estimates, credit notes, advance invoices and delivery notesdocument.<action>- one action across all document types, e.g.document.created,document.updated,document.voided,document.paid
Deliveries always carry the concrete event name (e.g. credit_note.updated). A webhook receives at most one delivery per event, even if several entries match.
Payload format
Every webhook delivery sends a JSON body with this structure:
{ "event": "invoice.created", "data": { ... }, "timestamp": "2024-01-15T10:30:00.000Z"}Delivery headers
Each delivery includes these headers:
| Header | Description |
|---|---|
X-Webhook-Signature | HMAC-SHA256 signature: sha256=<hex> |
X-Webhook-Timestamp | Unix timestamp (seconds) when the payload was signed |
X-Webhook-Event | Event type (e.g. invoice.created) |
X-Webhook-Delivery | Delivery ID, the same on every retry of this event to this webhook (use it as the idempotency key) |
X-Webhook-Id | Webhook endpoint ID |
User-Agent | SpaceInvoices-Webhook/1.0 |
Verifying signatures
Signatures use HMAC-SHA256. To verify:
- Get the raw request body (do not parse it first)
- Compute
HMAC-SHA256(secret, body)using your webhook secret - Compare the hex digest with the value after
sha256=inX-Webhook-Signature
const crypto = require('crypto');
function verifySignature(secret, payload, signature) { const expected = crypto .createHmac('sha256', secret) .update(payload) .digest('hex'); return signature === `sha256=${expected}`;}Retry policy
Failed deliveries are retried up to 5 attempts with exponential backoff:
| Attempt | Delay |
|---|---|
| 1 | Immediate |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 2 hours |
Delays are minimums, measured from the previous attempt; retries are sent by a job that runs every 5 minutes. Each attempt has a 10-second timeout.
HTTP status codes 400, 401, 403, 404, 405, and 410 are permanent failures: they are not retried, and the webhook is deactivated immediately. The webhook is also deactivated after the 5th failed attempt.
Account owners and admins get an email when the first attempt of a delivery fails and when a failed delivery deactivates the webhook. Re-enable it with PATCH /webhooks/{id} and {"active": true}.
Events that happen while a webhook is inactive are not queued and have no delivery record, so re-enabling does not replay them. Retries scheduled before deactivation can still be sent after the webhook is re-enabled. To catch up, re-list the resources that changed since the webhook was deactivated; GET /webhooks/{id}/deliveries shows only deliveries attempted before that.
The Webhook object
Attributes
Masked secret (only shown on create and rotate)
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
Default: {}
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "whsec_****...****",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}Create a new webhook
/webhooksCreate a webhook endpoint. The response includes the full secret which is only visible on creation and when rotated.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Body parameters
The HTTPS URL to send webhook events to. Cannot target localhost, private IPs, or internal domains.
Events that trigger this webhook. Use an exact event name, for every event of one resource, document. or document.* for every document type, or * for every event.
Optional description for this webhook
Whether webhook is active
Default: true
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.create({
url: "https://example.com/webhooks",
events: [
"invoice.created"
]
}, {
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
Default: {}
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}List all webhooks
/webhooksRetrieve a paginated list of webhooks for the entity. Secrets are masked in the response.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Query parameters
Number of results per request.
Default: 10
Opaque cursor to fetch the next page of results. Reuse only with the same effective ordering. Use the value from pagination.next_cursor in the previous response.
Opaque cursor to fetch the previous page of results. Reuse only with the same effective ordering. Use the value from pagination.prev_cursor in the previous response.
Whether to include the total count of items in pagination.total.
Default is true.
When false, pagination.total returns -1 for better performance.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.list({
limit: 20,
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
Pagination metadata including cursors and result counts
{
"data": [
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "whsec_****...****",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}
],
"pagination": {
"total": 1,
"next_cursor": null,
"prev_cursor": null,
"has_more": false
}
}Get a webhook by ID
/webhooks/{id}Retrieve a single webhook. The secret is masked in the response.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.get('whk_6595a27b5d35015c3ef0c3fd', {
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
Masked secret (only shown on create and rotate)
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
Default: {}
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "whsec_****...****",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}Update a webhook
/webhooks/{id}Update webhook URL, events, active status, or description.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
Body parameters
The HTTPS URL to send webhook events to. Cannot target localhost, private IPs, or internal domains.
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.update('whk_6595a27b5d35015c3ef0c3fd', {
url: "https://new-url.example.com/webhooks"
}, {
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
Masked secret (only shown on create and rotate)
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
Default: {}
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "whsec_****...****",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}Delete a webhook
/webhooks/{id}Permanently delete a webhook endpoint. Pending deliveries will be cancelled.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
await sdk.webhooks.delete('whk_6595a27b5d35015c3ef0c3fd', {
entity_id: "YOUR_ENTITY_ID"
});
console.log('Deleted successfully');Returns
{
"success": true
}Test a webhook
/webhooks/{id}/testSend a test event to the webhook endpoint to verify connectivity.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.testWebhook('whk_6595a27b5d35015c3ef0c3fd', {
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
{
"id": "whd_6595a27b5d35015c3ef0c3fd",
"webhook_id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"event_type": "webhook.test",
"status": "success",
"request_body": {
"event": "webhook.test",
"data": {}
},
"response_status": 200,
"response_body": "OK",
"error_message": null,
"attempt": 1,
"max_attempts": 1,
"next_retry_at": null,
"duration_ms": 150,
"created_at": "2024-01-01T00:00:00.000Z",
"completed_at": "2024-01-01T00:00:00.150Z"
}List webhook deliveries
/webhooks/{id}/deliveriesRetrieve a paginated list of delivery attempts for a specific webhook.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
Query parameters
Number of results per request.
Default: 10
Opaque cursor to fetch the next page of results. Reuse only with the same effective ordering. Use the value from pagination.next_cursor in the previous response.
Opaque cursor to fetch the previous page of results. Reuse only with the same effective ordering. Use the value from pagination.prev_cursor in the previous response.
Whether to include the total count of items in pagination.total.
Default is true.
When false, pagination.total returns -1 for better performance.
Returns
Pagination metadata including cursors and result counts
{
"data": [
{
"id": "whd_6595a27b5d35015c3ef0c3fd",
"webhook_id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"event_type": "invoice.created",
"status": "success",
"request_body": {
"event": "invoice.created",
"data": {
"id": "inv_123"
}
},
"response_status": 200,
"response_body": "OK",
"error_message": null,
"attempt": 1,
"max_attempts": 5,
"next_retry_at": null,
"duration_ms": 120,
"created_at": "2024-01-01T00:00:00.000Z",
"completed_at": "2024-01-01T00:00:00.120Z"
}
],
"pagination": {
"total": 1,
"next_cursor": null,
"prev_cursor": null,
"has_more": false
}
}Rotate webhook secret
/webhooks/{id}/rotate-secretGenerate a new signing secret for the webhook. The previous secret is immediately invalidated.
Header parameters
Entity ID on which the request is made. Auto-selected when only one entity exists, required when multiple entities exist.
Path parameters
Unique resource identifier. Prefix depends on the resource, for example inv_, cus_, or ent_.
import SpaceInvoices from '@spaceinvoices/js-sdk/sdk';
const sdk = new SpaceInvoices('YOUR_API_KEY');
const response = await sdk.webhooks.rotateWebhookSecret('whk_6595a27b5d35015c3ef0c3fd', {
entity_id: "YOUR_ENTITY_ID"
});
console.log(response);Returns
Custom string key-value data for your own use, with up to 50 properties. Keys are opaque and may contain periods. Useful for storing external IDs, tags, or integration data.
Default: {}
{
"id": "whk_6595a27b5d35015c3ef0c3fd",
"entity_id": "ent_6595a27b5d35015c3ef0c3fd",
"url": "https://example.com/webhooks",
"description": null,
"secret": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
"events": [
"invoice.created",
"invoice.paid"
],
"active": true,
"metadata": {},
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z"
}