SEO Title: Day 2: Invalid Base64 Encoding or Empty XML Error #irbapi #base64error
Focus Keyphrase: IRB base64 invoice error
Meta Description: Solve the IRB e-invoice API error caused by invalid base64-encoded XML or empty content. Ensure proper encoding and UTF-8 headers in Laravel.
IRBM API Error: Invalid Base64 or Missing XML
When submitting invoices to IRBM, you may encounter this vague but common response:
{
"error": "Invalid payload",
"details": "Invoice XML is not properly base64 encoded or is empty"
}
What This Error Means
IRBM expects:
- Your XML to be UTF-8 encoded
- The entire XML document to be base64-encoded
- The result passed in the
invoice
field of your POST request
Common Mistake
Submitting raw XML instead of base64:
// ❌ WRONG: sending XML directly
'body' => [
'invoice' => $signedXml
]
Correct Laravel Implementation
// Ensure UTF-8 and base64 encoding
$encodedXml = base64_encode(mb_convert_encoding($signedXml, 'UTF-8', 'auto'));
$response = Http::withToken($accessToken)->post(
'https://preprod-api.myinvois.hasil.gov.my/api/v1.0/invoices',
['invoice' => $encodedXml]
);
Extra Debug Tips
- ✅ Always use
DOMDocument::saveXML()
— not string concatenation - ✅ Confirm XML starts with
- ✅ Log
strlen($encodedXml)
— if it’s too small (e.g. 10–20 bytes), something’s wrong
How to Simulate This Error
You can simulate this error by:
- Forgetting to sign the XML (empty document)
- Accidentally trimming the output
- Encoding an empty string:
base64_encode('')
Coming Up in Day 3
We’ll cover the IRBM error: “Digest Mismatch (DS322)” — the nightmare caused by canonicalization or transform issues.
Tags: #IRBIntegration #Base64Error #LaravelEInvoice #EncodingIssue #UBLXML