# Invoices with correct invoice hash failing with hash error on production

**URL:** <https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696>\
**Category:** Clearance and Reporting\
**Created:** [September 7, 2023, 2:08pm UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696 "2023-09-07T14:08:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinay.hegde](https://avatars.discourse-cdn.com/v4/letter/v/da6949/32.png) [@vinay.hegde](https://zatca1.discourse.group/u/vinay.hegde)\
**Post date:** [September 7, 2023, 2:08pm UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/1 "2023-09-07T14:08:35Z")

</div>

There are multiple invoices that have failed with the error ‘The invoice hash API body does not match the (calculated) Hash of the XML’.

We have verified the hash of all the invoices and they all are correct. Retried submitting the same invoice 12 times and they are still in rejected state.  
Please suggest how to resolve this error and how many retries ideally are required for resolving this error.  
There are other error codes which are resolved upon retrying but the number if retries is not always consistent i.e. sometime they get resolved with 3 retries while sometimes they get resolved with 5-6 or more retries.

---

<div class="post-metadata">

**Author:** ![kiaziz](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiaziz](https://zatca1.discourse.group/u/kiaziz)\
**Post date:** [September 10, 2023, 7:25am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/2 "2023-09-10T07:25:26Z")

</div>

you can generate the API request body (JSON request) simply by using the SDK and this command :  
**Fatoora -invoicerequest -invoice [_invoice.xml_]**

just to ensure that the invoice encoded and the hash parameter sent in the request both are identical.

Regards,

---

<div class="post-metadata">

**Author:** ![vinay.hegde](https://avatars.discourse-cdn.com/v4/letter/v/da6949/32.png) [@vinay.hegde](https://zatca1.discourse.group/u/vinay.hegde)\
**Post date:** [September 11, 2023, 2:45pm UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/3 "2023-09-11T14:45:59Z")

</div>

Thanks! Did this and the hash and encoded invoice match exactly.  
Even after this the invoice is not getting cleared after multiple retries.

---

<div class="post-metadata">

**Author:** ![kiaziz](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiaziz](https://zatca1.discourse.group/u/kiaziz)\
**Post date:** [September 12, 2023, 6:08am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/4 "2023-09-12T06:08:16Z")

</div>

what is the error returned for which the invoice is not cleared ?

---

<div class="post-metadata">

**Author:** ![vinay.hegde](https://avatars.discourse-cdn.com/v4/letter/v/da6949/32.png) [@vinay.hegde](https://zatca1.discourse.group/u/vinay.hegde)\
**Post date:** [September 12, 2023, 6:25am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/5 "2023-09-12T06:25:10Z")

</div>

“The invoice hash API body does not match the (calculated) Hash of the XML” - This is the error message. I have verified and the calculated hash matches with the invoice hash in the API body.

---

<div class="post-metadata">

**Author:** ![kiaziz](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiaziz](https://zatca1.discourse.group/u/kiaziz)\
**Post date:** [September 12, 2023, 6:37am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/6 "2023-09-12T06:37:48Z")

</div>

please provide us with the XML and your request through the RM to investigate it more

---

<div class="post-metadata">

**Author:** ![vinay.hegde](https://avatars.discourse-cdn.com/v4/letter/v/da6949/32.png) [@vinay.hegde](https://zatca1.discourse.group/u/vinay.hegde)\
**Post date:** [September 15, 2023, 9:32am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/7 "2023-09-15T09:32:01Z")

</div>

Thanks! We have asked the finance team to submit the xml through the RM for further investigation. Please check and update.

---

<div class="post-metadata">

**Author:** ![rcamartin](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rcamartin](https://zatca1.discourse.group/u/rcamartin)\
**Post date:** [September 20, 2023, 7:31am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/8 "2023-09-20T07:31:15Z")

</div>

Hi. I have the same issue previously and I got this problem when submitting invoice with arabic text. make sure that your xml is properly converted into UTF8 before hashing it and the same xml in UTF8 is submitted. you can try using postman to check and use this link ([https://www.base64encode.org/](https://www.base64encode.org/)) to convert your xml to UTF8. Please let me know if you got it fix

---

<div class="post-metadata">

**Author:** ![kiaziz](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kiaziz](https://zatca1.discourse.group/u/kiaziz)\
**Post date:** [September 24, 2023, 6:56am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/9 "2023-09-24T06:56:38Z")

</div>

Dear @rcamartin  
please note that hashing is working fine with invoices containing arabice or english text,  
please share with us the invoice to investigate it more.

Regards,

---

<div class="post-metadata">

**Author:** ![rcamartin](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@rcamartin](https://zatca1.discourse.group/u/rcamartin)\
**Post date:** [September 24, 2023, 7:11am UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/10 "2023-09-24T07:11:51Z")

</div>

Hi Sir,

Like I’ve said, we manage to fix the issue after we got a meeting with our RM and we found out that the xml were submitting were not in UTF8 format which clears our issue. It might be the same problem they are facing.

---

<div class="post-metadata">

**Author:** ![mali-qb-solutions.us](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@mali-qb-solutions.us](https://zatca1.discourse.group/u/mali-qb-solutions.us)\
**Post date:** [April 28, 2025, 10:47pm UTC](https://zatca1.discourse.group/t/invoices-with-correct-invoice-hash-failing-with-hash-error-on-production/696/11 "2025-04-28T22:47:53Z")

</div>

I hope this post saves someone a few hours of head-scratching.

If you keep getting “ **invoice hash does not match XML** ” even after following the docs to the letter, the culprit is often a hidden **UTF-8 BOM** at the start of your unsigned XML. That three-byte marker (`EF BB BF`) changes the SHA-256 digest.

Remove it before you canonicalise or sign:

```auto
// strip any leading UTF-8 BOM
const unsignedXml = builder.buildObject(xmlObj).replace(/^\uFEFF/, "");

```

With the BOM gone, your InvoiceHash will match the hash that ZATCA expects.
