Delivery
A generated document reaches its reader three ways. The response to a generation carries a download link, for your own code to fetch. A document can also be mailed to the people it is for, with a link that needs no account. And your systems can be told of each document through webhooks: signed events posted to an endpoint you register.
Email delivery
Ask for it with the generation: delivery on Generate. Each recipient
receives an email of their own, from documents@docpayload.com under your organization's name, with a button that
opens the document in the browser. Email delivery is off until an administrator turns it on.
{
"templateId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"data": { "invoice": { "number": "2026-1042" } },
"delivery": {
"reference": "order-1042",
"email": {
"to": ["customer@example.com"],
"subject": "Your invoice 2026-1042",
"message": "Thank you for your order.",
"language": "en",
"replyTo": "billing@example.com",
"attach": true
}
}
}
| Field | Type | Required | Description |
|---|---|---|---|
delivery.reference | string | No | Your own reference, at most 200 characters, returned on every event about this document and its emails |
delivery.email.to | string[] | No | One to 10 addresses. Each receives its own email and its own link; an address named twice is mailed once. Left out or empty, the organization's fixed recipients |
delivery.email.subject | string | No | One line of at most 200 characters. Left out, the subject names your organization: "Acme Corp sent you a document" |
delivery.email.message | string | No | Shown above the button, line breaks kept, at most 2,000 characters |
delivery.email.language | string | No | en (default) or fr: the language the email and its link's pages are written in |
delivery.email.replyTo | string | No | One address the recipient's reply goes to |
delivery.email.attach | boolean | No | Attach the document as well as link it, as a file of its own named after the document's metadata.title (else its stored name). A document over 3 MB is linked only, and the email says so |
The response carries what the delivery became, one entry for each email queued:
{
"status": "succeeded",
"documentId": "d4e5f6a7b8c90123456789abcdef0123",
"fileName": "docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf",
"errorCodes": [],
"problems": [],
"delivery": {
"reference": "order-1042",
"email": [
{ "id": "3f2a1b4c-5d6e-4f70-8a9b-0c1d2e3f4a5b", "to": "customer@example.com", "documentIds": ["d4e5f6a7b8c90123456789abcdef0123"], "status": "queued", "attempts": 0, "sentAt": null, "error": null, "openedAt": null, "renewalOf": null }
]
}
}
The document and its emails are recorded together: an email is never queued for a document that was not stored. A
document generated with an errorCodes entry is not mailed: each of its emails is recorded held, its error naming
the codes, and a delivery.email.failed event says so with status held, so a receiver tells it from a refusal. Read problems, fix what is yours to fix, and generate again.
The link
The link in an email opens the document in the browser, with no account and no sign-in. It names the one address it
was sent to and works for 48 hours, any number of times. The first fetch of the link is recorded on the delivery
(openedAt): a reader opening it, or the recipient's mail filter checking it before the reader sees the email, which
many do, so the stamp says the link was reached, not that a person read the document. Past 48 hours, the link shows a page offering a new link, sent to the same address and nowhere else, at
most three times a day. A document you delete is no longer available through any link.
Status
status | Meaning |
|---|---|
queued | Waiting to be sent |
sent | Accepted by the mail service: the most that can be known of an email until it is opened |
failed | Will not be sent: the mail service refused it, or every try was spent. error says why |
held | Never sent: a document it carries has problems. error names the codes |
A send the mail service may recover from is tried again after 1 minute, 5 minutes, 30 minutes and 2 hours.
Mail a stored document
POST /v1/{tenantId}/documents/{documentId}/deliveries
The body is the delivery object above, email required. The answer is 202 Accepted, the email queued rather than
sent, with the same delivery object as in a generation's response; 404 when the document is not yours or was
deleted. GET on the same path lists the
document's emails, newest first, those it was sent alone and those it went in with others.
Mail several documents together
POST /v1/{tenantId}/documents/deliveries
{
"documentIds": ["d4e5f6a7b8c90123456789abcdef0123", "e5f6a7b8c90123456789abcdef012345"],
"reference": "invoices-2026-11",
"email": { "to": ["customer@example.com"], "attach": true }
}
Up to 100 stored documents reach each address together, never one email a document. Each is listed in the email with
a link of its own, in the order named; email is the object above.
With attach, each document is attached as a file of its own, never in an archive. One email carries attachments up
to 3 MB together, so a series larger than that is sent as a sequence: each email carries the next documents in order
up to that size, and its subject and heading say which it is, "(1 of 3)", until all have gone. A document over 3 MB
travels linked in the email it falls in. Without attach, every document goes in one email.
The answer is 202 Accepted and lists each email queued, its documentIds among them; 404 when a document named is
not yours.
Both take an Idempotency-Key, as a generation does: a request whose answer was lost, sent again with its key, is
answered as the first was and queues no second email. See Retrying safely.
Read one email
GET /v1/{tenantId}/deliveries/{id}
Answers one entry as above. Your webhooks are told the same with delivery.email.sent and
delivery.email.failed.
Turn it on
Email delivery is off for a new organization. An administrator turns it on in the app, under Settings, Email delivery, by accepting its statements for the organization: that it mails only people who expect its documents or whom it may contact, and stops when asked; that it is responsible for the documents and messages it sends, which DocPayload delivers as they are; that DocPayload processes each recipient's address, and whether a link was opened, only to deliver them; and that every email says it was sent on the organization's behalf, with a way to report it. Who accepted them, and when, is kept and shown there. When the statements change, they are asked for again.
Turning delivery off refuses new emails, and the emails still queued are not sent.
The same page lists the allowed domains. With domains listed, documents are mailed only to addresses at those domains, and a request naming any other address is refused whole. A domain covers itself only: list a subdomain on its own. With none listed, any address may be mailed. The emails still queued are held to the list too.
It also lists the fixed recipients: up to 10 addresses, such as an accounting inbox, that an email goes to when its request names none. They are held to the allowed domains.
With automatic delivery on, every document generated through the API with an API key, whose request asks for no
delivery of its own, is mailed to the fixed recipients: linked, and attached when it is 3 MB or less. Documents made in
the app are not mailed unasked. The mail is admitted as an asked one is, so a generation it would be refused for is
refused: a document the organization expects mailed is never stored unmailed.
| Method | Path | Does |
|---|---|---|
GET | /v1/{tenantId}/email-delivery | Whether delivery is on, the current termsVersion, who accepted it and when, allowedDomains and fixedRecipients |
PUT | /v1/{tenantId}/email-delivery/terms | Turns delivery on: { "termsVersion": "..." }, the version the administrator read |
DELETE | /v1/{tenantId}/email-delivery/terms | Turns delivery off |
PUT | /v1/{tenantId}/email-delivery/allowed-domains | Replaces the list: ["example.com"], at most 50; [] allows any address |
PUT | /v1/{tenantId}/email-delivery/fixed-recipients | Replaces the fixed recipients: ["accounts@example.com"], at most 10 |
PUT | /v1/{tenantId}/email-delivery/auto-delivery | { "enabled": true } mails every API document to the fixed recipients; needs one listed |
Limits
| Code | Status | When |
|---|---|---|
RULE_VIOLATION | 400 | A field breaks a rule above: an address that is not one, more than 10, a subject on two lines, more than 100 documents; or a document named has problems (its problems say what) |
EMAIL_DELIVERY_NOT_ON_PLAN | 402 | The organization is on the free plan, which has no email delivery |
EMAIL_DELIVERY_NOT_ENABLED | 403 | Email delivery is off for the organization: an administrator has not accepted the current statements |
EMAIL_RECIPIENT_NOT_ALLOWED | 403 | An address is outside the organization's allowed domains; the message names it |
EMAIL_DELIVERY_CEILING | 429 | The organization's emails in the last 24 hours, with these, would pass 1,000. Each email of a sequence counts |
Each refusal is answered before anything is generated: nothing is stored, mailed or billed. Delivery itself is never billed.
Webhooks
Register an endpoint, and every event it asks for is posted to it as JSON, signed under Standard Webhooks. An organization holds up to 5 endpoints.
Register an endpoint
POST /v1/{tenantId}/webhooks
{
"url": "https://example.com/hooks/docpayload",
"events": ["document.generated", "document.failed", "delivery.email.sent", "delivery.email.failed"],
"includeDocument": false,
"description": "ERP inbound"
}
| Field | Type | Required | Description |
|---|---|---|---|
url | string | Yes | An https address on the public internet. It may not carry a user name or password, and may not name an address inside a private network |
events | string[] | Yes | The events to post, from the table below |
includeDocument | boolean | No | Carry the document itself inside document.generated, base64, when it is 3 MB or less |
description | string | No | At most 200 characters |
The answer is 201 with the endpoint and its signing secret, whsec_.... The secret is shown in this answer
and never again: keep it where your receiver can read it.
| Method | Path | Does |
|---|---|---|
GET | /v1/{tenantId}/webhooks | Lists your endpoints, in value |
GET | /v1/{tenantId}/webhooks/{id} | One endpoint |
PATCH | /v1/{tenantId}/webhooks/{id} | Changes url, events, includeDocument, description, or enabled |
DELETE | /v1/{tenantId}/webhooks/{id} | Deletes the endpoint; its attempts are kept |
POST | /v1/{tenantId}/webhooks/{id}:rotate-secret | A new secret, shown once; the old one keeps signing beside it for 24 hours |
POST | /v1/{tenantId}/webhooks/{id}:test | Posts a webhook.ping event and answers with the attempt |
GET | /v1/{tenantId}/webhooks/{id}/attempts | The endpoint's attempts, newest first, each with its status code and the first kilobyte of the answer: a page in value, maxpagesize at most 200, and nextLink while there are more |
The same is in the app, under Settings, Webhooks.
Events
| Event | Posted when | data |
|---|---|---|
document.generated | A document is generated and stored | documentId, fileName, title, contentType, sizeBytes, requestId, source, errorCodes, problems, reference, downloadUrl, and document or documentOmitted where the endpoint asked for the document |
document.failed | A generation wrote no document | requestId, source, errorCodes, problems, reference |
requestId is the Request-Id the generation was answered with, so an event finds the request that caused it.
| delivery.email.sent | An email was accepted by the mail service | deliveryId, documentIds, recipient, reference, status (sent) |
| delivery.email.failed | An email will not be sent | deliveryId, documentIds, recipient, reference, status (failed, or held for one never sent because a document it carries has problems), error |
A request refused before rendering is no event: nothing was generated. downloadUrl is fetched with your API
credentials, as the generation's own link is. fileName is the name the API serves the document under; title is the
document's own title, or null, and is what an emailed reader is handed the file by, so the two names can be matched.
What is posted
POST https://example.com/hooks/docpayload
Content-Type: application/json
webhook-id: evt_7c1e0f6a2b3d4e5f8091a2b3c4d5e6f7
webhook-timestamp: 1762176000
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
{
"type": "document.generated",
"timestamp": "2026-11-03T12:00:00.000Z",
"data": {
"documentId": "d4e5f6a7b8c90123456789abcdef0123",
"fileName": "docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf",
"title": "Invoice INV-2026-1042",
"contentType": "application/pdf",
"sizeBytes": 31744,
"requestId": "4bf92f3577b34da6a3ce929d0e0e4736",
"source": "template",
"errorCodes": [],
"problems": [],
"reference": "order-1042",
"downloadUrl": "https://api.docpayload.com/v1/{tenantId}/assets/docs/docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf"
}
}
Verify a delivery
The signature is an HMAC-SHA256, keyed with the bytes the secret's base64 holds after whsec_, of the webhook-id,
the webhook-timestamp and the body exactly as received, joined by full stops. Compare it with each v1, value of
the header in constant time, and refuse a timestamp more than five minutes from your clock. Any Standard Webhooks
verifier does this; with no library at all:
import base64, hashlib, hmac, time
def verify(secret: str, headers: dict, body: bytes) -> bool:
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = f"{headers['webhook-id']}.{headers['webhook-timestamp']}.".encode() + body
expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
fresh = abs(time.time() - int(headers["webhook-timestamp"])) <= 300
return fresh and any(hmac.compare_digest(expected, value.removeprefix("v1,"))
for value in headers["webhook-signature"].split())
Verify the body before parsing it: a body read and written back out is not the body that was signed.
Retries
Answer with any 2xx within 20 seconds, then do the work. Anything else is a failure, and the event is posted again
after 5 seconds, 5 minutes, 30 minutes, 2, 5, 10, 14, 20 and 24 hours, a tenth earlier or later, about 75 hours in
all. A redirect is a failure: register the address it points to. 429, 502 and 504 are read as "slow down", and
a Retry-After is honoured, up to a day. 410 Gone switches the endpoint off at once.
Every try of one event carries the same webhook-id, and a try can arrive twice: record the ids you have handled and
skip one you have seen. Events are not posted in order.
An endpoint whose every attempt has failed for 3 days, with no success in between, is switched off, and your
organization's administrators are emailed. Fix it, then switch it back on with PATCH {"enabled": true} or in the
app.