Batch hooks: retrieving documents in bulk

Retrieve documents periodically in bulk via batch hooks: period, maxBatchSize and ZIP archive.

By default the PSB sends a webhook notification immediately for every received document. At high volumes it can be more efficient to process documents periodically in bulk. With a batch hook the PSB collects all events during a configurable period and packages them into a ZIP archive.

How does a batch hook work?

A batch hook listens on a topic (for example InvoiceReceived) and collects all events that come in during a given period. After the period ends, the PSB creates a ZIP file containing all the documents associated with those events. The PSB then publishes a new topic ({Topic}Batched) so you can download the archive.

The flow is as follows:

  1. The PSB receives documents and registers events
  2. The batch hook collects events until the period has elapsed or the maximum count is reached
  3. The PSB creates a ZIP archive of all collected documents
  4. A {Topic}Batched event is published (for example InvoiceReceivedBatched)
  5. Your webhook receives the batched event and downloads the ZIP archive
Creating a batch hook

Register a hook via the API with a batch://zip action:

{
  "action": "batch://zip?period=00:15:00&maxBatchSize=100",
  "topics": ["InvoiceReceived"]
}
Parameters
ParameterDefaultDescriptionperiod00:15:00 (15 minutes)The collection period in the format hh:mm:ss. After this period the batch is closed and the ZIP archive is created.maxBatchSize100The maximum number of events per batch. If this count is reached before the end of the period, the batch is closed immediately.

Tip: choose the period and maxBatchSize based on your document volume. At low volumes you can set a longer period (for example one hour). At high volumes a shorter period with a higher maxBatchSize is more practical.

Publish topic

After closing a batch the PSB publishes a new event on the topic {Topic}Batched. The naming follows a fixed pattern:

Source topicBatched topicInvoiceReceivedInvoiceReceivedBatchedOrderReceivedOrderReceivedBatched

Set up a regular webhook on the batched topic to retrieve the ZIP archive:

{
  "action": "https://jouw-endpoint.nl/batches",
  "topics": ["InvoiceReceivedBatched"],
  "secret": "jouw-geheime-sleutel"
}
ZIP archive

The ZIP file contains all documents collected in the batch, each as a separate XML file. The file names are based on the documentId. The archive can be downloaded via the URL provided in the batched event.

Combining with regular hooks

You can combine batch hooks with regular webhooks. For example, use a regular webhook for immediate processing of urgent documents and a batch hook for periodic bulk import into your ERP system. Make sure you do not process documents twice if you have both hooks on the same topic.

Note: batch hooks use the same retry logic as regular webhooks. If the batched event is not delivered successfully, the PSB retries for up to 5 days.

Frequently asked questions
Which topic should I listen on to retrieve the ZIP archive from a batch hook?

After the collection period ends, the PSB publishes an event on {Topic}Batched, for example InvoiceReceivedBatched when the source topic is InvoiceReceived. Register a regular webhook on that batched topic to receive the download URL and retrieve the ZIP file.

How do period and maxBatchSize work together?

period (default 15 minutes) sets how long events are collected before the batch is closed; maxBatchSize (default 100) closes the batch earlier if that limit is reached first. Tune both to your volume: longer periods when you have few documents, shorter periods or higher limits at peak traffic.

Can I combine a batch hook and a direct webhook on the same topic?

Yes, but watch for duplicate processing: if both use the same source topic, the same document may arrive twice. Only use both if you handle that explicitly, for example immediate delivery for urgent cases and batch for bulk import.


See the full API specification at psb.econnect.eu for all configuration options.

View the API documentation