Integration patterns
Send Bulk Envelopes
Send one personalized envelope per record from a DOCX template, paced under the rate limit, retried safely, and tracked with topics and metadata.
When you need to send the same document to many recipients with personalized details (for example, renewal notices, offer letters, or sales proposals), loop through your data set and create one envelope per record. This guide sends offer letters from a DOCX template.
How It Works
SignatureAPI has no bulk-send endpoint. You create one envelope per recipient by calling POST /v1/envelopes for each record in your data set. Each call uses the same DOCX template URL with that record’s data and recipient.
Diagram as text
Parts
- Records: One row per recipient: name, email and the template's merge values.
- Send loop: Sends one request at a time, pauses between requests, and waits and retries on a `429`.
- Webhook handler: Marks each record done as its `envelope.completed` event arrives, matched by `envelope_metadata`.
- API rate limit: 10 requests per second per API key by default. Requests over the limit get `429 Too Many Requests`.
- One envelope per record: Each with the same template URL, its own data and recipient, and the batch's topic and metadata.
- Events: Events from every envelope in the batch, in any order.
Connections
- Records to Send loop
- Send loop to API rate limit: POST /v1/envelopes
- API rate limit to One envelope per record: accepted
- One envelope per record to Events: status changes
- Events to Webhook handler: webhooks
Three things matter in the loop:
- Pace the requests. API requests are rate limited per API key: 10 requests per second by default. Over the limit, the API answers
429 Too Many Requests. - Check every response. A request that fails creates no envelope; log it and retry it or report it.
- Tag the batch. A batch topic and a record ID in
metadatalet you find each envelope later, match webhook events to records, and check for duplicates before a retry.
Prepare Your Data
Structure your data as an array of records. Each record contains the recipient details and the merge fields your template requires. If your data is a CSV file, map its columns to the same shape.
const records = [
{ id: "emp_001", name: "Jane Doe", email: "jane.doe@example.com", position: "Senior Engineer", startDate: "December 1, 2026", salary: "$120,000" },
{ id: "emp_002", name: "John Smith", email: "john.smith@example.com", position: "Product Manager", startDate: "December 15, 2026", salary: "$115,000" },
{ id: "emp_003", name: "Maria Garcia", email: "maria.garcia@example.com", position: "Design Lead", startDate: "January 5, 2027", salary: "$110,000" }
];The example template has the merge fields {{candidateName}}, {{position}}, {{startDate}} and {{salary}}, and the placeholder [[candidate_signs_here]] for the signature.
Example template
Download the offer letter template used in this example.
The Envelope Payload
Each iteration sends a request like this one, for the first record:
POST /v1/envelopes HTTP/1.1
Host: api.signatureapi.com
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"title": "Offer Letter for Jane Doe",
"message": "Please review and sign your offer letter.",
"topics": ["offers_2026_q4"],
"metadata": {
"batch_id": "offers-2026-q4",
"record_id": "emp_001"
},
"documents": [
{
"url": "https://pub-9cb75390636c4a8a83a6f76da33d7f45.r2.dev/docs-samples/acme-offer-letter-template.docx",
"format": "docx",
"data": {
"candidateName": "Jane Doe",
"position": "Senior Engineer",
"startDate": "December 1, 2026",
"salary": "$120,000"
},
"places": [
{
"key": "candidate_signs_here",
"type": "signature",
"recipient_key": "candidate"
}
]
}
],
"recipients": [
{
"type": "signer",
"key": "candidate",
"name": "Jane Doe",
"email": "jane.doe@example.com"
}
]
}Create Envelopes in a Loop
For each record, send the request, then check the response. On a 429, wait and send the same request again: a rate-limited request was rejected before anything was created, so retrying it can’t create a duplicate. The wait is the Retry-After header when the response has one, and otherwise doubles from 1 second.
const TEMPLATE_URL = "https://pub-9cb75390636c4a8a83a6f76da33d7f45.r2.dev/docs-samples/acme-offer-letter-template.docx";
const BATCH = { topic: "offers_2026_q4", id: "offers-2026-q4" };
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function createEnvelope(record) {
const body = JSON.stringify({
title: `Offer Letter for ${record.name}`,
message: "Please review and sign your offer letter.",
topics: [BATCH.topic],
metadata: { batch_id: BATCH.id, record_id: record.id },
documents: [
{
url: TEMPLATE_URL,
format: "docx",
data: {
candidateName: record.name,
position: record.position,
startDate: record.startDate,
salary: record.salary
},
places: [{ key: "candidate_signs_here", type: "signature", recipient_key: "candidate" }]
}
],
recipients: [{ type: "signer", key: "candidate", name: record.name, email: record.email }]
});
for (let attempt = 0, wait = 1000; attempt <= 5; attempt++, wait *= 2) {
const response = await fetch("https://api.signatureapi.com/v1/envelopes", {
method: "POST",
headers: { "X-API-Key": process.env.SIGNATUREAPI_KEY, "Content-Type": "application/json" },
body
});
if (response.ok) return response.json();
if (response.status !== 429) {
// 4XX: fix the record. 5XX or a network error: check for a duplicate before retrying (below).
throw new Error(`${record.id}: ${response.status} ${await response.text()}`);
}
const retryAfter = Number(response.headers.get("Retry-After"));
await sleep(retryAfter > 0 ? retryAfter * 1000 : wait);
}
throw new Error(`${record.id}: still rate limited after 5 retries`);
}
const failed = [];
for (const record of records) {
try {
const envelope = await createEnvelope(record);
console.log(`${record.id}: envelope ${envelope.id}`);
} catch (error) {
failed.push(record.id);
console.error(error.message);
}
await sleep(200); // about 5 requests per second, under the default limit
}
console.log(`Done. Failed records: ${failed.join(", ") || "none"}`);Avoid Duplicates When You Retry
POST /v1/envelopes has no idempotency key. If a request times out or returns a 5XX error, the envelope may still have been created, so sending the request again can create a second envelope for the same record.
Before you retry such a record, list the batch’s envelopes by topic and look for its record_id in metadata:
GET /v1/envelopes?topic=offers_2026_q4 HTTP/1.1
Host: api.signatureapi.com
X-API-Key: YOUR_API_KEYFollow links.next in each response until it is null to read the whole batch. Retry only the records that have no envelope. See Pagination and List Envelopes.
Track Your Envelopes
When you receive webhook events, the envelope_metadata property in each event carries the batch_id and record_id you set. Use them to mark each record as sent, completed, or failed in your own data. Events from different envelopes arrive in any order.
Keep Learning
- Learn more about document templates and merge field syntax.
- Use webhooks to track envelope completion across your batch.
- Organize envelopes with topics and metadata for filtering and reporting.
- Review rate limiting to understand request limits.