Webhooks
This page uses these terms:
- Your organization: the account of your company in the Wafeq e-invoicing ASP portal. Your webhook endpoints belong to your organization.
- Mode: Live or Sandbox. Each mode has its own webhook endpoints, signing secrets and events.
- Grant: the permission that a business gives to your organization. A grant has an ID (
tgr_…) and scopes. The scopes are the permissions that the business approved. - Taxpayer: a business from which your organization has an active grant. Its ID is the Taxpayer ID (
txpay_…). - Document: an invoice or a credit note. Its ID is the document ID (
inv_…). - Delivery: the transfer of a document to the buyer's e-invoicing provider, on Peppol.
- Report: the copy of a document that Wafeq e-invoicing ASP sends to the FTA, the UAE Federal Tax Authority. One document can have more than one report.
- Webhook endpoint: a URL on your server. Wafeq e-invoicing ASP sends events to this URL.
- Event: a message that Wafeq e-invoicing ASP sends to your webhook endpoint when something changes.
- Signing secret: the secret of one webhook endpoint. Your server uses it to check that an event comes from Wafeq e-invoicing ASP.
Use this page when you build the webhook receiver of your app. To add a webhook endpoint, refer to Set up your organization. To use the document events, refer to Track a document.
Example: one invoice, three events. Your app submits an invoice to a buyer on Peppol. Wafeq e-invoicing ASP delivers it to the buyer's provider and sends document.sent. Some minutes later, the buyer's provider answers that it forwarded the invoice to the buyer. Wafeq e-invoicing ASP sends document.status. Later, the FTA accepts the report. Wafeq e-invoicing ASP sends document.reported. Each event gives your app a result that it cannot get at the time of the submission.
The events
Wafeq e-invoicing ASP sends eight events. You select the events for each webhook endpoint.
| Event | Wafeq e-invoicing ASP sends it when |
|---|---|
taxpayer.created | Your organization gets its first active grant from a business. |
taxpayer.updated | The details or the status of a taxpayer change, or your grants from it change. |
taxpayer.deleted | Your organization loses its last active grant from a taxpayer. |
document.sent | The delivery of a document to the buyer's provider ends. |
document.status | The delivery of a document changes after that. |
document.reported | The FTA answers a report. |
document.received | A document from another business arrives for a taxpayer. |
batch.completed | Each document of a batch that your organization sent has its answer. |
Taxpayer events
Why they matter. These events tell your app which businesses it can submit documents for. They also tell your app when the registered details of a taxpayer change. Wafeq e-invoicing ASP takes the seller details of each document from these registered details.
taxpayer.createdcomes when the business approves your app. It comes also if your callback does not receive the authorization code.taxpayer.updatedcomes when the taxpayer starts to deregister in EmaraTax, or when its registered details change. It also comes when your grants from it change.taxpayer.deletedcomes when the business revokes your last grant, when your app revokes it, or when the deregistration of the taxpayer completes. After this event, your app cannot call the API for this taxpayer.
The data of the three events contains these fields:
| Field | Value |
|---|---|
taxpayer_id | The Taxpayer ID (txpay_…). |
tin | The TIN of the taxpayer. |
participant_id | The Peppol ID of the taxpayer: 0235: followed by the TIN. |
name | The name of the taxpayer. |
status | The status of the taxpayer, for example onboarded, deregistration_pending or disconnected. |
grants | Your active grants from the taxpayer: grant_id, label, scopes and metadata of each grant. |
profile | The registered details: legal_name, trade_name, vat_number, legal_registration and address. |
deleted | true. Only taxpayer.deleted has this field. |
taxpayer.updatedalso hasprevious_attributes, next todata. It contains only the fields that changed, with their old values.taxpayer.deletedcontains the last data before the change.- After each taxpayer event, read
GET /grantsto get the current state. Events can arrive late. Do not restore a connection because of a latetaxpayer.createdevent.
document.sent
document.sentWhy it matters. This event tells your app how the handover of the document to the access point of the buyer's provider ended. The answer of the buyer's provider comes later, in document.status: a forward to the buyer, a confirmed delivery, or a rejection. No event tells you that the buyer approved the invoice.
| Field | Value |
|---|---|
document_id | The document ID (inv_…). |
source_id | The value that your app sent in source_id. |
invoice_number | The number of the document. |
invoice_type_code | The document type. |
status | How the handover ended. delivered: the access point of the buyer's provider gave a receipt. delivery_status is then received_by_ap, or the answer of the provider if it came first. In Sandbox, a delivery to a test buyer has delivery_status: sent until the simulated provider answers, and a delivery to an active Sandbox taxpayer has sent for up to 2 minutes, then delivered_confirmed or forwarded, as the app of the buyer's organization fetches the document or not. Refer to Receive a document in the Sandbox. failed and attention_required: the same values as delivery_status. Refer to Delivery errors. |
recipient_id | The address of the delivery: the Peppol ID of the buyer, or an FTA placeholder address. |
seller_id, buyer_id | The Peppol IDs of the seller and the buyer. |
currency, total | The currency and the amount due of the document. |
document.status
document.statusWhy it matters. The buyer's provider can reject a document after the delivery. A rejection, or a missed deadline, can make it necessary to submit a correction. This event also shows the progress of a queued delivery.
| Field | Value |
|---|---|
document_id | The document ID. Old events can have no document_id. Refer to the note below the table. |
source_id | The value that your app sent in source_id. |
invoice_number | The number of the document. |
delivery_status | The new status of the delivery. For the values, refer to Track a document. |
response_code | The answer of the buyer's provider (MLS). AB: the provider forwarded the document to the buyer, and it has no way to verify that the document arrived. AP: the provider has a verifiable confirmation that the document arrived on the side of the buyer. RE: the provider did not deliver the document. AB and AP are both a successful delivery, and neither tells you that the buyer approved the invoice. The provider answers one time only. Other events have null. |
reason_code | The reason for the change. In a delivery receipt, it is the main reason of the provider, for example BV, SV or FD. When the provider gives FD with other reasons, it is FD. |
reason_codes | Only in a delivery receipt: every reason code that the provider gave, in upper case. An empty list when the provider gave none. |
detail | Only in a delivery receipt: the text of the provider, at most 4,000 characters. null when the provider sent no text. |
reporting_recovery | In a delivery receipt, in a deadline event and in the event of a corrected document that replaces this document: how Wafeq e-invoicing ASP handles the report of the document after a rejection or a missed deadline. Its trigger tells why, and it does not change. null when there is nothing to handle. Refer to the list below the table. |
message_id | The ID of the message that carried the document. The response of the submission gives the same value. |
delivery_job_id | The ID of a queued delivery. |
replacement_document_id | The document ID of a corrected document that replaces this document. |
- Old delivery receipts, sent before
document_idwas added, have nodocument_id. For them, usesource_idto find the document. If your app sent nosource_id, usemessage_id. - Wafeq e-invoicing ASP also sends
document.statuswhen it accepts a queued document, and when the queued delivery changes.
The values of reporting_recovery.trigger:
c3_validation_rejected: the buyer's provider rejected the document withBVorSV.c3_delivery_rejected: the buyer's provider rejected the document withFD. It could not deliver the document.c3_rejection_unclassified: the buyer's provider rejected the document, and the reason is not clear: no reason,BWonly, an unknown reason, orFDtogether withBVorSV.c3_transport_overdue: the access point of the buyer's provider gave no receipt for a queued delivery in time. Refer to The attempts of a queued delivery.c3_mls_overdue: the buyer's provider did not answer a queued delivery within 10 minutes. Wafeq e-invoicing ASP does not use this trigger at this time. When the provider does not answer, Wafeq e-invoicing ASP keeps the report, and adocument.statusevent comes withc3_deadlines.state: attention_requiredandreason_code: c3_mls_overdue.
document.reported
document.reportedWhy it matters. Wafeq e-invoicing ASP reports each document to the FTA. This event gives the answer of the FTA. Show this status to your users. It tells them if the FTA accepted the report of the document.
| Field | Value |
|---|---|
document_id | The document ID. |
source_id | The value that your app sent in source_id. |
tax_authority_status | REPORTED (the FTA accepted the report), NOT_COMPLIANT (the FTA rejected the report) or WITHDRAWN. |
submission_id | The ID of the report (tdd_…). |
document_type_code | The type of report: S, R or W. Refer to the list below the table. |
supersedes_id | For an R report: the submission_id of the report that it replaces. |
fta_status | The answer of the FTA: accepted or rejected. |
reason_code, detail | The reason that the FTA gives, if it gives one. |
reporting_recovery | The same object as in document.status, for the document of the report, as it is when the FTA answers. Its trigger tells why Wafeq e-invoicing ASP withdrew the report. null when the document has none. |
The types of report:
S: the first report of the document.R: a corrected report, after the FTA rejected a report. Wafeq e-invoicing ASP does not deliver the document again.W: the withdrawal of a report. Wafeq e-invoicing ASP withdraws a report when the buyer's provider rejects the document, or when a queued delivery misses its deadline. The event then hastax_authority_status: WITHDRAWN, andreporting_recovery.triggertells which. In this event,reporting_recovery.statecan still bewithdrawal_queued. The state becomeswithdrawnshortly after, inGET /invoices/{document_id}.
After a withdrawal, for any reporting_recovery.trigger, your app can submit a correction with the same number: corrected content after BV or SV, the same content after any other cause. The correction is a new document with its own document_id, and the same source_id is allowed. Refer to Correct or cancel a document.
A document can have more than one report. Keep each event with the report that its submission_id identifies. GET /invoices/{document_id}/reports gives all the reports of a document. Old events can have no submission_id, document_type_code or supersedes_id.
document.received
document.receivedWhy it matters. This event tells your app that another business sent a document to a taxpayer, for example the invoice of a supplier. Your app can then get the document and show it to the user.
| Field | Value |
|---|---|
document_id | The document ID of the received document. |
invoice_number | The number of the document. |
invoice_type_code | The document type. |
seller_id, buyer_id | The Peppol IDs of the seller and the buyer. |
currency, total | The currency and the amount due of the document. |
status | received. |
To get the document, send GET /invoices/{document_id}/xml.
The access point of the sender can send the same document again, for example when it did not get an answer. Wafeq e-invoicing ASP keeps one copy and sends document.received once when the same taxpayer receives the same supplier's document UUID (cbc:UUID). A new transport message ID does not create another document; a different document UUID does, even when its number and amounts match.
Fetch the document within 2 minutes. Wafeq e-invoicing ASP answers the sender's provider one time only. When your app fetches the document with GET /invoices/{document_id}/xml within 2 minutes of its reception, the answer is that the document reached the buyer (MLS AP): the sender gets delivered_confirmed. Without that fetch, the answer is that the document was forwarded (MLS AB): the sender gets forwarded, for good. A later fetch does not change the answer.
The 2xx answer of your endpoint to the event only stops the retries of the event. It does not tell the sender anything. For what counts as the fetch, a second copy of a document, and a held document, refer to Receive a document.
batch.completed
batch.completedWhy it matters. This event tells your app that a batch that it sent is complete: each document of the batch has its answer. Your app can then read the answers. Refer to Send many documents at once.
| Field | Value |
|---|---|
batch_id | The batch ID (bat_…). |
status | completed. |
document_count | The number of documents in the batch. |
counts | The number of documents that are accepted, failed and unconfirmed. pending is 0. |
created_at, completed_at | When Wafeq e-invoicing ASP accepted the batch, and when the last document got its answer. |
taxpayer_id | The Taxpayer ID (txpay_…). |
grant_ids | Your active grants from the taxpayer with invoices:write or invoices:read. |
To get the answer of each document, send GET /batches/{batch_id}/items. Each accepted document of the batch also has its own document events.
Which events your organization receives
These rules decide which events Wafeq e-invoicing ASP sends to your organization:
- Taxpayer events go to each organization that has an active grant from the taxpayer.
- Document events go to your organization only if one of your active grants from the taxpayer has the
invoices:readscope. Without this scope, your organization gets no document events, also for the documents that your app submits. - Received documents also need the
inbound:readscope. This applies todocument.received, and to the other events about a received document. - Documents of other apps. A taxpayer can approve more than one app. With
invoices:read, your organization receives the events of all the documents of the taxpayer.data.issued_byidentifies the organization that submitted the document. - Revoked grants. When your last grant from a taxpayer stops, document events stop immediately. This includes events that Wafeq e-invoicing ASP did not send yet.
- Batch events go only to the organization that sent the batch, while it has an active grant from the taxpayer with
invoices:writeorinvoices:read. Other organizations with a grant from the same taxpayer do not get them. - No past events. A new grant or a new webhook endpoint does not get the events of the past. To get earlier documents, use
GET /invoicesand the other list endpoints.
In Live, your organization can pay for received documents with document credits. A document credit is a prepaid unit of your organization. If your organization has no free credit, Wafeq e-invoicing ASP holds the document.received event. Wafeq e-invoicing ASP sends it when your organization gets more credits. While Wafeq e-invoicing ASP holds the document, your app cannot fetch it. If the hold lasts more than 2 minutes, the sender gets forwarded, unless another organization fetches the document in time. Refer to Receive a document.
The format of an event
Wafeq e-invoicing ASP sends each event as a POST request with a JSON body. The body has these fields:
| Field | Value |
|---|---|
id | The ID of the event (evt_…). It is the same value as the webhook-id header. |
type | The name of the event, for example document.reported. |
version | The version of the format: "1". |
created_at | The time when Wafeq e-invoicing ASP created the event. |
participant_id | The Peppol ID of the taxpayer. In a test event, it is null. |
environment | The mode: live or sandbox. |
test | true for a test event, for example an event that you send from the portal. Otherwise false. |
data | The data of the event. |
In each document event, data also contains these fields:
taxpayer_id: the Taxpayer ID.grant_ids: the IDs of your grants that give your organization this event.issued_by: the ID of the organization that submitted the document. A received document does not have this field.
Example of a document.reported event. The example shows only some of the fields in data:
{
"id": "evt_6f1c2b7d0e9a4c3b8f5d2a1e0c9b8a7f6e5d4c3b2a1f0e9d8c7b6a5f4e3d2c1b",
"type": "document.reported",
"version": "1",
"created_at": "2026-10-15T09:12:44.512031+00:00",
"participant_id": "0235:1999200000",
"environment": "live",
"test": false,
"data": {
"document_id": "inv_0123456789ABCDEFGHIJ",
"source_id": "erp-invoice-8812",
"tax_authority_status": "REPORTED",
"fta_status": "accepted",
"submission_id": "tdd_A1b2C3d4E5f6G7h8J9k0",
"document_type_code": "S",
"supersedes_id": null,
"taxpayer_id": "txpay_K1m2N3p4Q5r6S7t8U9v0",
"grant_ids": ["tgr_W1x2Y3z4A5b6C7d8E9f0"]
}
}Process an event: the four steps
Wafeq e-invoicing ASP sends each event at least one time. Thus your server can receive the same event more than one time. Events can also arrive in a different order than the changes.
| Step | Action |
|---|---|
| 1 | Check the signature over the raw body. |
| 2 | Find duplicates with the webhook-id header. |
| 3 | Store the event, then answer with a 2xx status. |
| 4 | Put the events in order with created_at. |
Step 1: Check the signature over the raw body
Each request has three headers, in the Standard Webhooks format:
webhook-id: the ID of the event.webhook-timestamp: the time of the delivery attempt.webhook-signature: the signature of the ID, the timestamp and the body.
Check the signature with a Standard Webhooks library and the signing secret of the endpoint. Use the raw bytes of the body. Do not parse the JSON and serialize it again before the check, because this changes the bytes.
from standardwebhooks.webhooks import Webhook
event = Webhook(signing_secret).verify(raw_body, request_headers)The library also checks the timestamp. Keep this check, because it stops old requests that someone sends again. If the check fails, do not process the request.
Step 2: Find duplicates with the webhook-id header
webhook-id headerRead the webhook-id header. If your app already stored this ID, answer with a 2xx status and do nothing more.
Step 3: Store the event, then answer with a 2xx status
2xx statusStore the event in your database. Then answer with a 2xx status. Process the event after you answer.
If your server does not answer with a 2xx status, Wafeq e-invoicing ASP sends the event again later. Refer to Retries.
Step 4: Put the events in order with created_at
created_atUse created_at to put the events of one document or one taxpayer in the correct order. Do not let an older event replace the data of a newer event.
Retries
When a delivery attempt fails, Wafeq e-invoicing ASP sends the event again. Each new attempt is a retry.
A failed attempt. An attempt fails when one of these occurs:
- Your server answers with a status of
400or higher. - Your server does not answer in time.
- Wafeq e-invoicing ASP cannot connect to your server.
When your server answers with a 2xx status, the delivery is complete. Wafeq e-invoicing ASP sends no more attempts of this event to this endpoint.
The schedule. Wafeq e-invoicing ASP sends a maximum of 10 retries. The time before each retry is two times the time before the previous retry. The times are approximate.
| Attempt | Time after the previous attempt | Time after the first attempt |
|---|---|---|
| First | – | – |
| Retry 1 | 30 seconds | 30 seconds |
| Retry 2 | 1 minute | 1.5 minutes |
| Retry 3 | 2 minutes | 3.5 minutes |
| Retry 4 | 4 minutes | 7.5 minutes |
| Retry 5 | 8 minutes | 15.5 minutes |
| Retry 6 | 16 minutes | 31.5 minutes |
| Retry 7 | 32 minutes | 1 hour 4 minutes |
| Retry 8 | 1 hour 4 minutes | 2 hours 8 minutes |
| Retry 9 | 2 hours 8 minutes | 4 hours 16 minutes |
| Retry 10 | 4 hours 16 minutes | 8 hours 32 minutes |
If retry 10 also fails, Wafeq e-invoicing ASP stops the automatic retries of this event to this endpoint. The event is not lost. You can send it again from the portal.
What a retry contains.
- The body and the
webhook-idheader are the same as in the first attempt. Thus Step 2 finds a retry of an event that your app already stored. - The
webhook-timestampandwebhook-signatureheaders are new in each attempt. Thus the timestamp check of the library passes also for a late retry. - A retry can arrive after newer events. Step 4 puts the events in the correct order.
Each endpoint has its own retries. When one endpoint fails, Wafeq e-invoicing ASP continues to send events to your other endpoints. The retries of one endpoint do not delay the other endpoints.
Send an event again from the portal. In the Wafeq e-invoicing ASP portal, go to Developer Console → Events. Open the event, then select Delivery attempts. Select Retry delivery on a failed attempt. You can do this also after the automatic retries stop. The endpoint must be active. You cannot send again an event of a deleted endpoint.
Retries and revoked grants. When your last grant from a taxpayer stops, Wafeq e-invoicing ASP sends no new document events about this taxpayer. Retries of events that Wafeq e-invoicing ASP sent before the grant stopped can still arrive.
After the receiver works
These items are not steps. They tell you how to keep the receiver in good condition.
- Rotate the signing secret. You can rotate the signing secret of an endpoint in the Wafeq e-invoicing ASP portal. The old secret stays valid for 24 hours. Install the new secret on your server in this period.
- See the delivery attempts. The Wafeq e-invoicing ASP portal shows each delivery attempt and the answer of your server. You can send a failed event again from the portal. Refer to Retries.
- Rules for the endpoint URL. The URL must use HTTPS on port 443. Its host name must resolve only to public IP addresses. The URL must not contain a user name, a password or a fragment.
- Live and Sandbox. Add a webhook endpoint in each mode. Each endpoint has its own signing secret.
- Test events. To test your receiver, send a test event from Developer → Webhooks in the Wafeq e-invoicing ASP portal. The endpoint must be active. A test event uses one of the events of the endpoint. It contains
test: trueand changes no document. The one exception is the test bill of the portal (Receive a test bill, on Purchases → Bills, in the Sandbox only): it makes a bill for the taxpayer and sends itsdocument.receivedevent withtest: true.
Webhooks in Sandbox
- Wafeq e-invoicing ASP does not send reports to the FTA. Sandbox accepts each report approximately 5 seconds after Wafeq e-invoicing ASP accepts the document. Then a real
document.reportedevent comes, withtest: falseanddata.simulated: true. A test buyer can give another answer of the FTA. Refer to Test buyers. - Wafeq e-invoicing ASP simulates the delivery. The
document.statusevents of a simulated delivery containsimulated: true. A test buyer on Peppol sets the answer of its provider. After a rejection by the provider, a report that the FTA accepted is withdrawn:document.reportedcomes withtax_authority_status: WITHDRAWNandsimulated: true. Refer to Test buyers. - When the buyer is a Sandbox taxpayer, the organizations of the buyer receive
document.received. Fetch the document within 2 minutes to tell the sender that the buyer has it. - To test the other answers of the FTA, select an FTA answer for the test event. The endpoint must have the
document.reportedevent. The test event then containsREPORTED,NOT_COMPLIANTorFAILED.FAILEDoccurs only in these test events.
For more about Sandbox, refer to Sandbox.
Updated 5 days ago