> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prequel.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Batch API

> Implementing a Prequel Destination for your batch-based receiving endpoint

> [!NOTE]
>
> A Batch-based API endpoint is the recommended implementation for most use cases. Contact the Prequel team if you have questions.

A `webhook_batch` destination delivers multiple records in a single HTTP request.

For the API call to register a destination with Prequel, including a complete example, see [Create Destination](https://docs.prequel.co/import/import-api/overview.md).

> [card] [Register](#creating-your-destination-spec)
>
> Declare your schema and request template within Prequel.

> [card] [Receive](#delivery-format)
>
> Receive, download, and process the batch file.

> [card] [Respond](#response-codes)
>
> Return a status code Prequel acts on.

> [card] [Acknowledge](#acknowledgements)
>
> Optionally, report the outcome of each record.

## Authentication

Prequel signs every delivery request with the `X-Prequel-Webhook-Signature` header so your endpoint can validate the request originated from Prequel. Fetch the public key for verification from `GET /public/signatures/webhook-public-key`. See [Webhook headers](#webhook-headers) for the full header list and verification steps.

After verifying the request signature, you can optionally read `provider_id` and `load_id` from the envelope body to confirm the request belongs to an expected provider and load.

## Creating your destination spec

The `destination` object allows you to customize the contract between data shared by your customers and the shape Prequel provides to your receiving endpoint.

**Example:** Suppose you are importing a `users` table with string fields `id`, `email`, and `subscription`.

Below are four possible shapes for a `webhook_batch` destination. These are not exhaustive and features can be combined to confirm to your endpoint's requirements:

1. **Schema as body:** Records land in the `JSONL` artifact in the shape declared by `record_schema`, with no additional shaping.
2. **Custom body:** Use a `body` template to customize each record. Only supported when `format` is `json`.
3. **Routed by provider:** `uri` and/or `headers` vary at delivery time using the `ProviderID` delivery-level identifier.
4. **Destination per provider:** A separate destination is registered for each provider, with a `record_schema` that includes provider-specific custom fields.

> [tab] Schema as body
>
> #### Destination spec you register
>
> ```json title="POST /import/destinations" icon="brackets-curly" expandable theme={null}
> {
>   "name": "users-batch-destination",
>   "type": "webhook_batch",
>   "record_schema": {
>     "type": "object",
>     "properties": {
>       "id":    { "type": "string" },
>       "email": { "type": "string" },
>       "subscription": { "type": "string" }
>     },
>     "required": ["id", "email"]
>   },
>   "webhook_batch": {
>     "request_template": {
>       "method": "POST",
>       "uri": "https://example.com/prequel/batch",
>       "headers": { "Content-Type": "application/json" }
>     },
>     "format": "json"
>   }
> }
> ```
>
> #### What Prequel sends to your endpoint
>
> ```http title="Webhook request" expandable theme={null}
> POST https://example.com/prequel/batch
> Content-Type: application/json
> X-Prequel-Webhook-Timestamp: 2026-01-01T00:00:00Z
> X-Prequel-Webhook-Signature: 4f81c9a2...
> X-Prequel-Webhook-Digest: sha256=9c1e5b8d...
>
> {
>   "url": "https://storage.example.com/batches/f47ac10b.jsonl?X-Signature=...",
>   "batch_acknowledgement_url": "https://storage.example.com/acks/f47ac10b.json?X-Signature=...",
>   "format": "json",
>   "record_count": 2500,
>   "batch_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> ```
>
> ```json title="File at the presigned url" expandable theme={null}
> {
>   "id": "usr_001",
>   "email": "jane@acme.com",
>   "subscription": "pro",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_001"
> }
> {
>   "id": "usr_002",
>   "email": "raj@acme.com",
>   "subscription": "free",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_002"
> }
> ```
>
> **1. Name your destination**
>
> Set `name` (string, required) to a unique identifier for this destination within your account.
>
> **2. Set the destination type**
>
> Set `type` (string, required) to `webhook_batch` for batch deliveries.
>
> **3. Declare your record schema**
>
> Set `record_schema` (object, required) to a [JSON Schema (draft-07)](https://json-schema.org/specification-links#draft-7) document that declares the fields each record contains. Prequel validates records against this schema before delivery.
>
> **4. Configure the request template**
>
> Set `webhook_batch.request_template` (object, required) with the HTTP `method` (string, defaults to `POST`), `uri` (string, required), and optional `headers` (object). The `uri` and `headers` templates support the `.Prequel.*` namespace.
>
> **5. Pick a delivery format**
>
> Set `webhook_batch.format` (string, required) to one of `json`, `csv`, or `parquet`. See [Delivery format](#delivery-format) for what each option produces.
>
> **6. Tune optional throughput limits**
>
> Optionally set `webhook_batch.max_size_per_batch` (integer, default `24000`), `webhook_batch.max_batches_per_minute` (integer, default `10`), and `webhook_batch.max_concurrency` (integer, default `1`) to control delivery throughput.

> [tab] Custom body
>
> #### Destination spec you register
>
> ```json title="POST /import/destinations" icon="brackets-curly" expandable theme={null}
> {
>   "name": "users-batch-destination",
>   "type": "webhook_batch",
>   "record_schema": {
>     "type": "object",
>     "properties": {
>       "id":    { "type": "string" },
>       "email": { "type": "string" },
>       "subscription": { "type": "string" }
>     },
>     "required": ["id", "email"]
>   },
>   "webhook_batch": {
>     "request_template": {
>       "method": "POST",
>       "uri": "https://example.com/prequel/batch",
>       "headers": { "Content-Type": "application/json" },
>       "body": "{\"email\": \"{{.Record.email}}\", \"user\": {{jsonify .Record}}, \"is_deleted\": {{.IsDeleted}}, \"provider_id\": \"{{.Prequel.ProviderID}}\", \"load_id\": \"{{.Prequel.LoadID}}\"}"
>     },
>     "format": "json"
>   }
> }
> ```
>
> #### What Prequel sends to your endpoint
>
> ```http title="Webhook request" expandable theme={null}
> POST https://example.com/prequel/batch
> Content-Type: application/json
> X-Prequel-Webhook-Timestamp: 2026-01-01T00:00:00Z
> X-Prequel-Webhook-Signature: 4f81c9a2...
> X-Prequel-Webhook-Digest: sha256=9c1e5b8d...
>
> {
>   "url": "https://storage.example.com/batches/f47ac10b.jsonl?X-Signature=...",
>   "batch_acknowledgement_url": "https://storage.example.com/acks/f47ac10b.json?X-Signature=...",
>   "format": "json",
>   "record_count": 2500,
>   "batch_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> ```
>
> ```json title="File at the presigned url" expandable theme={null}
> {
>   "email": "jane@acme.com",
>   "user": {
>     "email": "jane@acme.com",
>     "id": "usr_001",
>     "subscription": "pro"
>   },
>   "is_deleted": false,
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> {
>   "email": "raj@acme.com",
>   "user": {
>     "email": "raj@acme.com",
>     "id": "usr_002",
>     "subscription": "free"
>   },
>   "is_deleted": false,
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> ```
>
> **1. Name your destination**
>
> Set `name` (string, required) to a unique identifier for this destination within your account.
>
> **2. Set the destination type**
>
> Set `type` (string, required) to `webhook_batch` for batch deliveries.
>
> **3. Declare your record schema**
>
> Set `record_schema` (object, required) to a [JSON Schema (draft-07)](https://json-schema.org/specification-links#draft-7) document that declares the fields each record contains. Prequel validates records against this schema before delivery.
>
> **4. Configure the request template with a body template**
>
> Set `webhook_batch.request_template` (object, required) with `method`, `uri`, `headers`, and `body`. The `body` template renders once per record while Prequel encodes the `JSONL` artifact, with access to record fields, the deletion flag, and delivery-level identifiers. The `uri` and `headers` templates render once per delivery and have access to delivery-level identifiers only. See [Template variables](#template-variables) for the full list of available variables. Body templates are only valid when `format` is `json`; selecting `csv` or `parquet` rejects the destination.
>
> **5. Pick a delivery format**
>
> Set `webhook_batch.format` (string, required) to one of `json`, `csv`, or `parquet`. See [Delivery format](#delivery-format) for what each option produces.
>
> **6. Tune optional throughput limits**
>
> Optionally set `webhook_batch.max_size_per_batch` (integer, default `24000`), `webhook_batch.max_batches_per_minute` (integer, default `10`), and `webhook_batch.max_concurrency` (integer, default `1`) to control delivery throughput.

> [tab] Routed by provider
>
> #### Destination spec you register
>
> ```json title="POST /import/destinations" icon="brackets-curly" expandable theme={null}
> {
>   "name": "users-batch-destination",
>   "type": "webhook_batch",
>   "record_schema": {
>     "type": "object",
>     "properties": {
>       "id":    { "type": "string" },
>       "email": { "type": "string" },
>       "subscription": { "type": "string" }
>     },
>     "required": ["id", "email"]
>   },
>   "webhook_batch": {
>     "request_template": {
>       "method": "POST",
>       "uri": "https://example.com/prequel/batch?provider={{.Prequel.ProviderID}}",
>       "headers": { "Content-Type": "application/json" }
>     },
>     "format": "json"
>   }
> }
> ```
>
> #### What Prequel sends to your endpoint
>
> ```http title="Webhook request" expandable theme={null}
> POST https://example.com/prequel/batch?provider=b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63
> Content-Type: application/json
> X-Prequel-Webhook-Timestamp: 2026-01-01T00:00:00Z
> X-Prequel-Webhook-Signature: 4f81c9a2...
> X-Prequel-Webhook-Digest: sha256=9c1e5b8d...
>
> {
>   "url": "https://storage.example.com/batches/f47ac10b.jsonl?X-Signature=...",
>   "batch_acknowledgement_url": "https://storage.example.com/acks/f47ac10b.json?X-Signature=...",
>   "format": "json",
>   "record_count": 2500,
>   "batch_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> ```
>
> ```json title="File at the presigned url" expandable theme={null}
> {
>   "id": "usr_001",
>   "email": "jane@acme.com",
>   "subscription": "pro",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_001"
> }
> {
>   "id": "usr_002",
>   "email": "raj@acme.com",
>   "subscription": "free",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_002"
> }
> ```
>
> **1. Name your destination**
>
> Set `name` (string, required) to a unique identifier for this destination within your account.
>
> **2. Set the destination type**
>
> Set `type` (string, required) to `webhook_batch` for batch deliveries.
>
> **3. Declare your record schema**
>
> Set `record_schema` (object, required) to a [JSON Schema (draft-07)](https://json-schema.org/specification-links#draft-7) document that declares the fields each record contains. Prequel validates records against this schema before delivery.
>
> **4. Route by provider in the request template**
>
> Set `webhook_batch.request_template` (object, required) with `method`, `uri`, and optional `headers`. Use `{{.Prequel.ProviderID}}` in `uri` and `headers` to route by the provider whose data is being delivered. These templates render once per delivery, before any records are selected. See [Template variables](#template-variables) for the full list of identifiers available.
>
> **5. Pick a delivery format**
>
> Set `webhook_batch.format` (string, required) to one of `json`, `csv`, or `parquet`. See [Delivery format](#delivery-format) for what each option produces.
>
> **6. Tune optional throughput limits**
>
> Optionally set `webhook_batch.max_size_per_batch` (integer, default `24000`), `webhook_batch.max_batches_per_minute` (integer, default `10`), and `webhook_batch.max_concurrency` (integer, default `1`) to control delivery throughput.

> [tab] Destination per provider
>
> #### Destination spec you register
>
> ```json title="POST /import/destinations" icon="brackets-curly" expandable theme={null}
> {
>   "name": "acme-corp-batch-destination",
>   "type": "webhook_batch",
>   "record_schema": {
>     "type": "object",
>     "properties": {
>       "id":      { "type": "string" },
>       "email":   { "type": "string" },
>       "subscription": { "type": "string" },
>       "tax_id":  { "type": "string" }
>     },
>     "required": ["id", "email", "tax_id"]
>   },
>   "webhook_batch": {
>     "request_template": {
>       "method": "POST",
>       "uri": "https://example.com/prequel/batch/acme-corp",
>       "headers": { "Content-Type": "application/json" }
>     },
>     "format": "json"
>   }
> }
> ```
>
> #### What Prequel sends to your endpoint
>
> ```http title="Webhook request" expandable theme={null}
> POST https://example.com/prequel/batch/acme-corp
> Content-Type: application/json
> X-Prequel-Webhook-Timestamp: 2026-01-01T00:00:00Z
> X-Prequel-Webhook-Signature: 4f81c9a2...
> X-Prequel-Webhook-Digest: sha256=9c1e5b8d...
>
> {
>   "url": "https://storage.example.com/batches/f47ac10b.jsonl?X-Signature=...",
>   "batch_acknowledgement_url": "https://storage.example.com/acks/f47ac10b.json?X-Signature=...",
>   "format": "json",
>   "record_count": 312,
>   "batch_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
>   "provider_id": "b6f2d1a4-3c58-4d0a-9e7b-2f1c8a9d4e63",
>   "load_id": "7e0c2b9a-5d14-4f6e-8a3b-9c47d0e15f28"
> }
> ```
>
> ```json title="File at the presigned url" expandable theme={null}
> {
>   "id": "usr_001",
>   "email": "jane@acme.com",
>   "subscription": "pro",
>   "tax_id": "US-77-1234567",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_001"
> }
> {
>   "id": "usr_002",
>   "email": "raj@acme.com",
>   "subscription": "free",
>   "tax_id": "US-77-7654321",
>   "prequel__is_deleted": false,
>   "prequel__record_id": "usr_002"
> }
> ```
>
> **1. Register one destination per provider**
>
> Create a separate destination for each provider whose requirements differ. Give each one a `name` (string, required) that identifies the provider it serves.
>
> **2. Set the destination type**
>
> Set `type` (string, required) to `webhook_batch` for batch deliveries.
>
> **3. Declare a provider-specific record schema**
>
> Set `record_schema` (object, required) to a [JSON Schema (draft-07)](https://json-schema.org/specification-links#draft-7) document that declares the fields this provider sends, including any custom fields unique to them. Prequel validates records against this schema before delivery.
>
> **4. Configure the request template**
>
> Set `webhook_batch.request_template` (object, required) with `method`, `uri`, and optional `headers`. Because the destination is scoped to a single provider, you can hard-code provider-specific routing into `uri` and `headers` without needing template variables.
>
> **5. Pick a delivery format**
>
> Set `webhook_batch.format` (string, required) to one of `json`, `csv`, or `parquet`. See [Delivery format](#delivery-format) for what each option produces.
>
> **6. Tune optional throughput limits**
>
> Optionally set `webhook_batch.max_size_per_batch` (integer, default `24000`), `webhook_batch.max_batches_per_minute` (integer, default `10`), and `webhook_batch.max_concurrency` (integer, default `1`) to control delivery throughput.

## Template variables

The `body` template has access to record fields, `.IsDeleted`, `.Tags`, and `.Prequel.*`; the `uri` and `headers` templates have access to `.Tags` and `.Prequel.*`.

| Variable | Type | Description |
| - | - | - |
| `{{.Record.<field>}}` | `any` | Value of a specific field from the record (e.g. `{{.Record.email}}`). The field must be declared in `record_schema`. (Available in `body` template only) |
| `{{.IsDeleted}}` | `boolean` | `true` when Prequel is delivering a record deletion, `false` otherwise. (Available in `body` template only) |
| `{{.Tags.<key>}}` | `string` | Value of a specific tag key applied to the load job. |
| `{{.Prequel.ProviderID}}` | `string` | Identifier for the provider whose data is being delivered. |
| `{{.Prequel.LoadID}}` | `string` | Identifier for the active load job. |
| `{{.Prequel.DestinationID}}` | `string` | Identifier for the destination receiving this delivery. |
| `{{.Prequel.StreamID}}` | `string` | Identifier for the stream this delivery came from. |
| `{{.Prequel.TenantID}}` | `string` | Identifier for the tenant the stream belongs to. |
| `{{.Prequel.IsTest}}` | `boolean` | `true` when the delivery comes from a test load. |

> [!TIP]
>
> **Rendering arrays and objects as JSON**
>
> `{{.Record.<field>}}` does not render an array or object field as JSON. For example, `["trial", "emea"]` renders as `[trial emea]`.
>
> Use `{{jsonify .Record.<field>}}` to render arrays or object fields as JSON. You can also use `{{jsonify .Record}}` to nest the full record under a key, or escape strings that may contain quotes or newlines. For an example, see [Custom body](#custom-body).
>
> `jsonify` rounds integers larger than 2^53. If you expect larger integers, such as 64-bit IDs, contact the Prequel team to discuss.

## Delivery format

Prequel makes one HTTP request per batch. The request body is an envelope with the following fields:

| Field | Type | Description |
| - | - | - |
| `url` | `string` | Presigned URL to the batch file. The URL itself carries a 24-hour TTL set by object storage. |
| `batch_acknowledgement_url` | `string` | URL to `PUT` acknowledgements for this batch to, expiring 24 hours after the delivery. See [Acknowledgements](https://docs.prequel.co/import/features/acknowledgements.md). |
| `format` | `string` | Format of the file at `url`. One of `json`, `csv`, or `parquet`. |
| `record_count` | `integer` | Number of records contained in the batch file. |
| `batch_id` | `string` | Unique identifier for this batch. |
| `provider_id` | `string` | Identifier for the provider whose data is being delivered. Omitted when unavailable. |
| `load_id` | `string` | Identifier for the active load job. Omitted when unavailable. |
| `tags` | `object` | Key-value string tags attached to the load job. Omitted when no tags are present. |
| `record_schema` | `object` | JSON Schema definition of the records in the batch. Omitted when not configured. |

Your endpoint reads the envelope, downloads the file at `url`, and processes the records inside. The `format` field on the destination controls what kind of file the URL points to:

| Format | File at `url` |
| - | - |
| `json` | `JSONL`. Each line is one record, optionally shaped by the `body` template. Without a `body` template, each line also carries `prequel__is_deleted` and `prequel__record_id` metadata fields. |
| `csv` | `CSV`. Includes `prequel__is_deleted` and `prequel__record_id` columns. Body templates are not supported. |
| `parquet` | `Parquet`. Includes `prequel__is_deleted` and `prequel__record_id` columns. Body templates are not supported. |

Without a `body` template, each delivered record also carries two Prequel-managed fields: `prequel__record_id`, a stable identifier for the record; and `prequel__is_deleted`, which is `true` when the record represents a deletion.

## Webhook headers

Prequel includes the following headers on every delivery request.

| Header | Description |
| - | - |
| `X-Prequel-Webhook-Signature` | SHA-256 RSA PKCS1 v1.5 signature of the payload. To verify, fetch the public key from `GET /public/signatures/webhook-public-key` and check the hex-decoded signature against the SHA-256 of `<X-Prequel-Webhook-Timestamp>.<raw body>` using PKCS1 v1.5. |
| `X-Prequel-Webhook-Timestamp` | RFC 3339 timestamp of when the request was sent. Reject stale timestamps to prevent replay attacks. |
| `X-Prequel-Webhook-Digest` | SHA-256 hash of the raw request body. |
| `Content-Type` | For batch deliveries, defaults to `application/json` unless overridden by the `headers` template. Record deliveries send only the headers the `headers` template specifies. |
| `X-Prequel-Is-Test` | Sent with value `true` only on deliveries from a test load. Acknowledgements uploaded for test deliveries are not ingested. |
| `X-Prequel-Idempotency-Key` | Unique idempotency key across retry attempts of the same batch or record within a load job. |

## Response codes

Your endpoint should return the following response codes.

| Code | When to return it | What Prequel does |
| - | - | - |
| `2xx` | You accepted the record. | Records the delivery as successful. |
| `429`, `503`, `504` with a `Retry-After` header | You are rate limited or temporarily unavailable and want the delivery attempted again. | Waits the interval the header specifies, capped at 30 seconds, then retries, for a maximum of three attempts per delivery. |
| `400`, `412`, `413`, `422` | The payload itself is the problem. Return `422` for schema or data validation failures, `413` when it exceeds your size limit, and `400` when the request is malformed. | Records the delivery as rejected by your endpoint. Does not retry. |
| Any other status | Your system could not accept the delivery. | Records the delivery as failed at the destination. This includes `500` and `502`, and a `429`, `503`, or `504` whose `Retry-After` header is absent or unparseable. Does not retry. |

For more detail on this retry behavior see:

> [card] [Delivery failure handling](https://docs.prequel.co/import/features/delivery-failure-handling.md)
>
> Retry rules, redelivery across loads, and the circuit breakers that stop a failing stream.

## Error codes

Prequel records the [error code](https://docs.prequel.co/import/logging/error-codes.md) below against every record in the batch, since the response describes the request rather than any individual record.

| Status | Error code | Title |
| - | - | - |
| `400`, `412`, `413`, `422`, `431` | `PRQL-XFUW` | Import Destination Batch Rejected |
| `403` | `PRQL-CNJK` | Import Destination Forbidden |
| `404` | `PRQL-VFTB` | Import Destination Not Found |
| `429` | `PRQL-WQKF` | Import Destination Rate Limited |
| `500` | `PRQL-PHOK` | Import Destination Internal Server Error |
| `502` | `PRQL-QPMF` | Import Destination Bad Gateway |
| `503` | `PRQL-HNNX` | Import Destination Service Unavailable |
| `504` | `PRQL-PRHQ` | Import Destination Gateway Timeout |
| Other `4xx` | `PRQL-IMEK` | Import Destination Client Error |
| Other `5xx` | `PRQL-TNXG` | Import Destination Server Error |

## Acknowledgements

Without acknowledgements, all records within a batch are forced to accept the same status from your webhook response. Acknowledging is what makes individually assigned, record-level failures visible to you and your customer to address.

> [card] [Acknowledgements](https://docs.prequel.co/import/features/acknowledgements.md)
>
> Report each record's downstream outcome back to Prequel once your system has processed it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.