Developers/Get started

Postbatch quick start

A Postbatch is a one-off mailing from a file: a template version, a product finish and destination, one CSV with the recipients and variables, a review of the validation, a quote and an approval that releases every valid item to a production run. The import, the review and the approval are available through the API and through the portal.

1. Create the Postbatch

The template needs a published version; the product follows from the version, the finish and destination must be allowed by the product specification.

TypeScript
const postbatch = await client.postbatches.create({
  body: {
    name: 'Spring mailing',
    templateVersionId: version.id,
    finish: 'silk',
    destination: 'NL',
  },
  idempotencyKey: 'crm-campaign-2026-spring',
});

The Postbatch starts in DRAFT with empty counts.

2. Upload the file

The CSV goes through an upload session of kind csv (up to 250 MB, UTF-8, UTF-16 with a byte order mark or Windows-1252, the delimiter is detected, a header row is required; the number of rows is limited only by your plan's maximum, when it sets one). PostBuddy reads the file as a stream, so its size does not matter beyond that. Attach the completed upload to the Postbatch; pass the mapping when you know the columns, or leave it out to receive a proposal from the template's mapping preset or the header names.

TypeScript
const upload = await client.uploads.create({
  kind: 'csv',
  fileName: 'spring.csv',
  contentType: 'text/csv',
  sizeBytes,
});
await fetch(upload.url, { method: 'PUT', body: bytes, headers: upload.headers });
await client.uploads.complete(upload.id);

const imported = await client.postbatches.startImport(postbatch.id, {
  body: {
    uploadId: upload.id,
    mapping: {
      name: '{{Naam}}',
      addressLine1: '{{Straat}} {{Huisnummer}}',
      postalCode: '{{Postcode}}',
      city: '{{Plaats}}',
      firstName: '{{Voornaam}}',
    },
  },
  idempotencyKey: 'crm-campaign-2026-spring-file-1',
});

An Idempotency-Key stays with the import it made for as long as the import exists (not only 24 hours): sending the same key with the same upload and mapping again answers that import, without cancelling and replacing it; the same key with another upload or mapping is refused with 422 idempotency_key_reused.

Every target (the recipient fields and every variable of the version's schema) takes an expression of static text and {{column}} references. The request answers 202 with the import; the Postbatch is IMPORTING. Poll GET /v1/postbatches/{id}/import until the import is MAPPED (a complete mapping), PARSED (a proposal with unmapped required targets; confirm a mapping with PUT .../import/mapping, optionally saved as the template's preset) or FAILED (the errors say why: no header, duplicate headers, no data rows, more rows than the plan allows). A new file for a DRAFT, IMPORTING or VALIDATED Postbatch replaces the earlier import and removes its items.

3. Process the rows

TypeScript
await client.postbatches.processImport(postbatch.id);

The rows become items in chunks: validated like Postflow items, deduplicated on the normalised address within the file (duplicates are kept as rows you can inspect with GET .../import/rows?status=DUPLICATE and keep after all with POST .../import/rows/{rowId}/keep), and matched against your suppression list. GET .../import carries the counts per outcome (processed, total, created, held with its older name valid, invalid with its older name needsAttention, suppressed, duplicates and refused, lines that could not be read); GET .../import/progress streams the same view as server-sent events. The rows are taken in chunks of 1,000 that commit with their counts, so an import that is interrupted goes on where it was without making a card twice. When the import is DONE the Postbatch is VALIDATED with its counts per item status and the events import.completed (the counts and errorRows, no personal data) and postbatch.validated fire.

errorRows on the import counts the rows that were not sent as they are. GET /v1/postbatches/{id}/import/errors answers them as a CSV (formula-safe): per row its number in the file, the outcome (invalid, suppressed, duplicate or refused), the reason and the row's own values per column. It holds personal data, so the key needs personal_data.read.

4. Review

GET /v1/postbatches/{id}/items lists the Postbatch's items with the item list conventions, for instance filter[status]=NEEDS_ATTENTION. Repair an item with PATCH /v1/items/{id}, cancel it with POST /v1/items/{id}/cancel, or skip every item that needs attention at once with POST .../skip-attention. A proof PDF of any item comes from POST .../proof with the itemId; poll the render it answers with.

5. Quote and approve

TypeScript
const quote = await client.postbatches.quote(postbatch.id);
// quantity, unitPriceCents, totalExclVatCents, totalInclVatCents, nextRun, plannedRuns
// 202 with the Postbatch APPROVING; approvePostbatch follows it until its approval ends
const approved = await client.approvePostbatch(postbatch.id, {
  skipInvalid: true,
  targetRunId: quote.plannedRuns[1]?.id,
});
// approved.status: APPROVED, or VALIDATED with approved.approval.state 'refused'

The quote prices the valid items on your pricing with the Postbatch quantity as the tier basis and shows the next run with its cutoff and expected delivery. The approval needs the postbatches.approve permission: it pins the template version, locks the quote in a price snapshot, reserves the amount from your balance (or checks your credit on invoice billing), cancels the items that need attention when skipInvalid is set (refused otherwise), and answers 202 with the Postbatch APPROVING. A job then moves every valid item to READY for the next planned run or for a later planned run chosen from plannedRuns, a thousand at a time, each with its reservation; approval on the Postbatch shows its state (working), done of total released, skipped and runs (when the chosen run passes its cutoff while the job runs, the rest of the items go to the next planned run of the group and runs names both). Poll GET /v1/postbatches/{id} (the SDKs' approvePostbatch and approve_postbatch do it for you) until it is no longer APPROVING. If the balance runs out while the items are released (other cards used it meanwhile; the whole quote is checked before the approval starts and refused with insufficient_balance, credit_limit_reached or payment_paused when it does not fit), the Postbatch goes back to VALIDATED (or PENDING_APPROVAL) with approval.state refused, its code and the items released so far kept; top up and approve again to release the rest. If the job fails after its retries, approval.state is failed and approving again tries again. Otherwise the Postbatch is APPROVED and postbatch.approved fires; it follows its items to SCHEDULED_FOR_RUN, IN_PRODUCTION and COMPLETED (postbatch.scheduled, postbatch.completed). Editors without the approval permission hand over with POST .../request-approval, which notifies the approvers.

6. Cancel

POST /v1/postbatches/{id}/cancel cancels a Postbatch up to APPROVED: a running import stops, the open items are cancelled and their reservations released; items already in production stay. It answers 202 with the Postbatch: a job cancels the items a thousand at a time, its progress in bulkAction (kind cancel, state working, done of total), and then the Postbatch is CANCELLED and postbatch.cancelled fires. POST .../skip-attention answers the same way with kind skip_attention. Asking again while the job works answers it as it is; when it failed after its retries (state failed, with its error) asking again goes on with the items still open. While one works, an approval, a new file and keeping a duplicate are refused with 409 invalid_postbatch_transition.

Retention

The uploaded CSV, the rows read from it, the sample and the error file are deleted seven days after the approval or the cancellation (a replaced file seven days after it was replaced); the import's purgedAt says when, and its counts stay. An import nobody touches for 30 days becomes EXPIRED and is purged at once; the cards it made stay as they are and a Postbatch still importing goes back to DRAFT. Owners, Admins, Editors and Approvers get the notification import.expiring a week before.

Events

Subscribe a webhook endpoint to postbatch.* and import.*, filtered on the Postbatch with filters.postbatchId when one integration follows one mailing: import.completed, import.failed, postbatch.validated, postbatch.approved, postbatch.scheduled, postbatch.completed and postbatch.cancelled. The item events of the Postbatch's items (item.*) carry postbatchId.