Send many documents at once
Use this page to send up to 500 documents of one taxpayer in one call, for example the invoices that your app issues at the end of the day. Wafeq e-invoicing ASP accepts the batch at once. Then it handles each document in the background, exactly as if your app had submitted it alone with Prefer: respond-async.
This page uses these terms:
- Batch: one call to
POST /batcheswith many documents of one taxpayer. A batch has an ID (bat_…). - Document: an invoice, a credit note, a self-billed invoice or a self-billed credit note.
- Taxpayer: a business from which your organization has an active grant. All the documents of a batch belong to the same taxpayer.
- Document key: the
Idempotency-Keyof one document. It is the key that the document would have if your app submitted it alone. - Batch key: the
Idempotency-Keyheader of the batch call. It makes the batch call safe to repeat. - Answer: the HTTP status and the body that the submission of a document alone would get, for example
202withstatus: queued.
When to use a batch
A single submission (POST /invoices and the other submission paths) handles one document in each call, with a limit of 60 calls a minute for each path. A batch carries up to 500 documents in one call. Each document is handled as its own queued submission:
- The same checks, the same billing, the same delivery and the same report to the FTA.
- The same webhook events for each accepted document.
- The same answer. A document that fails its checks gets the answer that it would get alone, and does not stop the other documents.
To check documents before your user finalizes them, keep using the /validate paths. Refer to Submit a document.
Before you start
- You know how to submit one document. Refer to Submit a document.
- The grant from the taxpayer has
invoices:write, to send the batch. To read the answers of the documents, the grant also needsinvoices:read. - Your webhook endpoint has the
batch.completedevent. Refer to Webhooks.
Send a batch: the five steps
| Step | Action | Result |
|---|---|---|
| 1 | Build the batch. | Each document has its type, its document key and its body. |
| 2 | Send the batch. | Wafeq e-invoicing ASP accepts the batch, or refuses all of it. |
| 3 | Wait for the batch to complete. | Each document has its answer. |
| 4 | Read the answers. | Your app knows which documents were accepted. |
| 5 | Handle the documents that failed. | Your app corrects them and sends them again. |
Step 1: Build the batch
Put the documents in documents. Each entry has three fields:
| Field | Value |
|---|---|
type | invoice, credit_note, self_billed_invoice or self_billed_credit_note. It selects the path that the document would take alone: POST /invoices, POST /credit-notes, POST /self-billing/invoices or POST /self-billing/credit-notes. |
idempotency_key | The document key: 1 to 128 visible ASCII characters. Make one key for each version of the document, as for a single submission. |
document | The request body of that path, unchanged. |
These rules apply:
- A batch has 1 to 500 documents. The types can be mixed.
- Each document needs its own key and its own number. Wafeq e-invoicing ASP refuses a batch with a key or a number that appears two times (
422). - A batch cannot replace a withdrawn document. A document with
corrects_document_idfails with422 correction_not_supported_in_batch. Send a replacement alone. Refer to Correct or cancel a document. - The body of the batch call can have up to 8 MiB.
Example with an invoice and a credit note:
{
"documents": [
{
"type": "invoice",
"idempotency_key": "erp-invoice-8812-3f9a1c",
"document": {
"invoice_number": "INV-2026-0042",
"issue_date": "2026-10-15",
"due_date": "2026-11-14",
"source_id": "erp-invoice-8812",
"customer": {
"id": "0235:1999200000",
"name": "Gulf Fresh Foods LLC",
"vat_number": "199920000000003",
"address": { "street": "Warehouse 7, Al Quoz Industrial 3", "city": "Dubai", "country": "AE", "country_subentity": "DXB" }
},
"line_items": [
{ "description": "Office chairs", "quantity": 10, "unit_price": 450, "tax_category": "S", "tax_percent": 5 }
]
}
},
{
"type": "credit_note",
"idempotency_key": "erp-credit-1203-77b2e0",
"document": {
"credit_note_number": "CN-2026-0007",
"issue_date": "2026-10-15",
"source_id": "erp-credit-1203",
"previous_invoice_source": "external",
"previous_invoice_number": "INV-2025-0911",
"credit_note_reason_code": "DL8.61.1.A",
"customer": {
"id": "0235:1999200000",
"name": "Gulf Fresh Foods LLC",
"vat_number": "199920000000003",
"address": { "street": "Warehouse 7, Al Quoz Industrial 3", "city": "Dubai", "country": "AE", "country_subentity": "DXB" }
},
"line_items": [
{ "description": "Returned office chair", "quantity": 1, "unit_price": 450, "tax_category": "S", "tax_percent": 5 }
]
}
}
]
}Step 2: Send the batch
Send the batch to POST /batches, with the headers of the taxpayer and a batch key:
curl https://api.wafeq.com/ae/v1/batches \
-H "Authorization: Api-Key $API_KEY" \
-H "x-ae-taxpayer-id: $TAXPAYER_ID" \
-H "x-ae-grant-id: $GRANT_ID" \
-H "Idempotency-Key: erp-run-2026-10-15" \
-H "Content-Type: application/json" \
-d @batch.jsonDo not send Prefer: respond-async. Each document of a batch is always a queued submission.
Wafeq e-invoicing ASP answers 202 at once. The Location header points to the batch:
{
"id": "bat_3kTq8VwM1zYc6RfH0pLa",
"status": "processing",
"document_count": 2,
"counts": { "pending": 2, "accepted": 0, "failed": 0, "unconfirmed": 0 },
"created_at": "2026-10-15T16:02:11.482000+00:00",
"completed_at": null
}The batch key makes the call safe to repeat. Store it before your app sends the batch. After a timeout or a lost connection, send the same batch again with the same batch key: Wafeq e-invoicing ASP returns the same batch, as it is now, and sends nothing two times. Wafeq e-invoicing ASP refuses the same batch key with a different body (409 idempotency_key_reused).
A refusal of the whole batch keeps nothing. Correct the cause, then send the same batch again with the same batch key:
| Answer | Cause | Next |
|---|---|---|
402 subscription_required | Live: your organization has no active subscription. | Buy or renew the subscription. |
402 wallet_insufficient_funds | Live: your organization has fewer free document credits than the batch has new documents. requiredDocuments and availableDocuments give the numbers. | Buy document credits, or send fewer documents. |
409 idempotency_key_reused | The batch key already sent a different batch. | Use a new batch key for a new batch. |
422 | The batch is not correct: the shape of the body, more than 500 documents, or a key or number that appears two times (duplicate_idempotency_key, duplicate_document_number, with the positions in indexes). | Correct the batch. |
429 too_many_open_batches | The taxpayer already has 5 unfinished batches from your organization. | Wait until one completes. |
429 | The rate limit of the path. Refer to Rate limits. | Wait, then send the same batch again. |
503 | A temporary problem: queued delivery is unavailable (queued_delivery_unavailable), the status of the subscription is unknown (billing_status_unavailable), or Wafeq e-invoicing ASP cannot save the batch (idempotency_unavailable). | Send the same batch again later, with the same batch key. |
Step 3: Wait for the batch to complete
The batch completes when each document has its answer. Then Wafeq e-invoicing ASP sends batch.completed to your organization:
{
"type": "batch.completed",
"data": {
"batch_id": "bat_3kTq8VwM1zYc6RfH0pLa",
"status": "completed",
"document_count": 2,
"counts": { "pending": 0, "accepted": 2, "failed": 0, "unconfirmed": 0 },
"created_at": "2026-10-15T16:02:11.482000+00:00",
"completed_at": "2026-10-15T16:02:19.905000+00:00",
"taxpayer_id": "txpay_0123456789abcdefghij",
"grant_ids": ["tgr_0123456789abcdefghij"]
}
}Without webhooks, read GET /batches/{batch_id} from time to time. status is completed when each document has its answer. GET /batches lists the batches of the taxpayer that your organization sent, the newest first.
The example shows only type and data. For the other fields of an event, refer to Webhooks.
Each accepted document also gets the events that it would get if your app had submitted it alone:
document.statuswhen Wafeq e-invoicing ASP accepts it, and after each step of its delivery.document.sentwhen the delivery to the buyer's provider ends. A document that Wafeq e-invoicing ASP reports to the FTA only has no delivery, so it gets nodocument.sent.document.reportedfor each answer of the FTA.
These events do not name the batch. Match them to your documents with document_id or source_id. Refer to Track a document.
Step 4: Read the answers
Send GET /batches/{batch_id}/items. Add status=failed to get only the documents that failed. The items come in the order of documents, 50 for each page by default. Use limit (up to 200) and offset to read the next pages.
{
"items": [
{
"index": 0,
"type": "invoice",
"invoice_id": "INV-2026-0042",
"source_id": "erp-invoice-8812",
"status": "accepted",
"response": {
"status_code": 202,
"body": { "success": true, "status": "queued", "invoice_id": "INV-2026-0042", "document_id": "inv_8sKq2LwN0yXb5QeG9oPz", "delivery_job_id": "djob_4hRt7UvW2xYz3AbC5dEf" }
}
},
{
"index": 1,
"type": "credit_note",
"invoice_id": "CN-2026-0007",
"source_id": "erp-credit-1203",
"status": "accepted",
"response": {
"status_code": 202,
"body": { "success": true, "status": "queued", "invoice_id": "CN-2026-0007", "document_id": "inv_7mLp4NxR2cVb9QaD6tHs", "delivery_job_id": "djob_9kVt3WpQ1sRx6NaB8cMe" }
}
}
],
"total": 2,
"limit": 50,
"offset": 0
}Each item has these fields:
| Field | Value |
|---|---|
index | The position of the document in documents, from 0. |
type | The type of the document. |
invoice_id | The number of the document. |
source_id | Your own ID for the document, if you sent one. |
status | pending, accepted, failed or unconfirmed. Refer to the list below. |
response | The answer of the document: status_code and body. null while the document is pending. |
The status of an item means:
pending: the document has no final submission answer yet. It may be waiting, being processed, or waiting for a retry.accepted: the answer is202, as for a queued submission.bodyhas thedocument_idand thedelivery_job_id. Track the document as usual. Refer to Track a document.failed: Wafeq e-invoicing ASP refused the document.responseis the answer that the document would get alone, for example422for a body that is not correct, or200withsuccess: falseandstatus: validation_failedfor a document that breaks a UAE rule. Refer to step 5.unconfirmed: Wafeq e-invoicing ASP cannot confirm if it accepted the document (409 idempotency_unconfirmed). It sends nothing more for this document. Refer to If a submission gets no response.
Step 5: Handle the documents that failed
Read the response of each failed document, as for a single submission. Refer to Errors.
For a separate failure example, consider a credit note whose line uses exempt VAT (tax_category: "E", tax_percent: 0) without the required VAT exemption reason code. Its item could have status: failed and this response:
{
"status_code": 200,
"body": {
"success": false,
"status": "validation_failed",
"invoice_id": "CN-EXEMPT-0001",
"error": "Invoice failed validation",
"validation_errors": [
{ "code": "SCH:ibr-167-ae", "message": "[ibr-167-ae]-Line VAT information (IBG-30) with Invoiced item VAT category code (IBT-151) as 'Exempt from VAT' MUST have a VAT exemption reason code (IBT-186).", "location": "/CreditNote/cac:CreditNoteLine[1]" }
]
}
}Check whether the answer was already saved. A batch replays an answer saved by an earlier submission without changing its document key. For example, an earlier single queued submission can save a 402. After you fix the cause, that key still returns the saved 402, including in a batch. Use a new document key in that case.
For answers produced by this batch, use these rules:
- The body does not match the API reference:
422with a list indetail,invalid_submission_payloadorcorrection_not_supported_in_batch. Wafeq e-invoicing ASP refuses the document before it uses the document key, as a single submission does, and keeps no answer for the key. Correct the document, then send it again with the same document key, alone or in a new batch. - The document is not correct, for example
200withsuccess: false, or422with a code such asdocument_type_mismatch. Wafeq e-invoicing ASP keeps this answer for the document key, as for a single submission. Correct the document, then send it with a new document key, alone or in a new batch. - A temporary problem, or a missing permission or credit:
402,403or503. Wafeq e-invoicing ASP accepted nothing and keeps no answer for the document key. Correct the cause, then send the same document again with the same document key. 409 idempotency_key_reused: another document already used this document key. Use a new key.409 idempotency_in_progress: a submission with this document key is still in progress, for example in another batch. Wait, then send the document again with the same key.409 idempotency_unconfirmed: an earlier submission with this key stopped, and its result is not known. Refer to If a submission gets no response.
When you put corrected or retried documents in a new batch, use a new batch key. Keep or replace each document key according to the rules above.
One key for each document
A document key works the same way in a batch and in a single submission:
- While a document waits in a batch, a single submission with its key gets
409 idempotency_in_progress. - If the document key has a saved answer, a single queued submission with the same key and the same body gets that answer again. If the batch released the key, follow step 5 to retry the document.
- A key that your app already used for a queued submission with the same body gets the saved answer of that submission in the batch.
- A key that your app first used without
Prefer: respond-asyncbelongs to a different request: the delivery mode is part of the key. In a batch, the document gets409 idempotency_key_reused.GET /submissions/receiptstill gives its first answer.
How Wafeq e-invoicing ASP handles a batch
- Order. Wafeq e-invoicing ASP handles the documents in the background. Batches take turns, so a large batch does not hold back the other batches, and new batches do not hold back a large one.
- Temporary problems. If a document is refused before acceptance because of a temporary problem, for example when Wafeq e-invoicing ASP cannot look for the buyer on Peppol, Wafeq e-invoicing ASP tries again for up to one hour. During this time, the document stays
pending. After that, the document fails with that answer, and its key stays free. - Credits. In Live, acceptance reserves one document credit. The credit is charged when delivery succeeds, or when the FTA receives a reporting-only document. A definitive failure before that releases the reservation; an uncertain outcome keeps it reserved. If the free credits run out while processing new documents in the batch, the remaining documents fail with
402 wallet_insufficient_funds, and their keys stay free. Buy credits, then send these documents again with the same document keys in a new batch. - Access. If your organization loses its grant from the taxpayer, the documents that Wafeq e-invoicing ASP has not accepted yet fail with
403, and their keys stay free. The documents that it already accepted continue. - Visibility. Only your organization can read its batches. Another organization gets
404, also when it has a grant from the same taxpayer.
Limits
| Limit | Value |
|---|---|
| Documents in a batch | 1 to 500 |
| Size of the body | 8 MiB |
Batch calls (POST /batches) | 10 a minute for your organization |
Reads (GET /batches…) | 120 a minute for each path |
| Unfinished batches | 5 for each taxpayer, for your organization |
Batches in Sandbox
Batches are free in Sandbox, as all Sandbox documents. Test buyers work in a batch as for a single queued submission, with one difference: a batch ignores R 3 to 7. These values simulate the answer of a single submission call. In a batch, the document is accepted as with R 0, and the other digits apply. Refer to Test buyers.
Next
Updated about 2 hours ago