Connecting a business system to LHDN MyInvois is less a coding task than a series of decisions. Some are about the business, some about the data, and some about who holds the keys. This guide sets out what a company has to decide and build, in the order the questions usually arrive.
Everything below that states a rule comes from LHDN’s published material, listed at the end. The rules change, so check the official sites before you plan a date or a threshold. We do not repeat deadlines here.
Step one: portal or API
MyInvois offers a web portal for issuing invoices by hand, and an API for systems that issue them automatically. The SDK site describes the API as the interface for taxpayer systems: ERP and similar systems submit issued documents to the Tax Authority and receive event notifications.
A rule of thumb that follows from that: a business that issues a handful of invoices a month may be served by the portal. A business with a POS, an online shop or an ERP producing invoices all day needs the API, because no one wants to key those documents in twice.
Step two: who authenticates
The SDK’s getting-started page names one prerequisite: the digital profile of the taxpayer. Your system then authenticates against the Login APIs to receive an access token. The same page describes an intermediary, a party that submits on behalf of a taxpayer.
The FAQ is specific about credentials. Production and Sandbox use different Client ID and Client Secret pairs, and production credentials do not work in the sandbox. An intermediary uses its own Client ID and Client Secret, and sees only the e-invoices it submitted for the taxpayer.
Step three: document types
The SDK lists eight e-invoice type codes.
| Code | Document |
|---|---|
| 01 | Invoice |
| 02 | Credit Note |
| 03 | Debit Note |
| 04 | Refund Note |
| 11 to 14 | The same four, as self-billed documents |
Decide which of these your business actually issues. A retailer may need only invoices and credit notes. A company that pays individuals or foreign suppliers will meet self-billing. The SDK describes the invoice as the main document type and maps every field to a UBL 2.1 path, with XML and JSON samples.
Step four: validation
Validation happens in two places: in your system before sending, and in MyInvois after.
Before sending, the FAQ advises validating the buyer’s TIN with the Validate Taxpayer’s TIN API. After sending, the document is validated by MyInvois, and the Get Document Details API returns the validation results. Three behaviours are worth designing for:
- The FAQ says an issuance date more than 72 hours before submission is rejected as too old.
- The FAQ says duplicates are flagged against other e-invoices processed in a 2-hour window.
- The FAQ says usage limits are enforced on Submit Documents.
Submission is asynchronous. Your system submits, then polls for the result, and has to handle a rejection as a normal outcome, not an exception.
Step five: digital signing
Each document is submitted signed. The SDK’s signature page sets out the technical rules:
- XAdES signature, SHA-256 hashing, RSA signing.
- An X.509 certificate issued by a certificate authority in Malaysia, valid on the submission date.
- The certificate carries the company name, the TIN and the business registration number, with key usage that includes Non-Repudiation and enhanced key usage for Document Signing.
- An enveloped signature placed in the UBL extensions. For JSON, the XML extension is transliterated into a foreign extension.
The FAQ adds that the sandbox offers document versions 1.0 and 1.1, and that signature validation is enabled only in version 1.1. A team that tests with 1.0 learns nothing about its signing.
Signing is where most teams lose time, because a small difference in what is hashed produces a signature that fails. It also puts a private key in your infrastructure, which is a security decision for the company, not only the developer.
Step six: consolidated e-invoices
Not every buyer wants an e-invoice. LHDN’s e-Invoice Specific Guideline, version 4.9, says that where the buyer does not require one, the supplier may issue a normal receipt and later consolidate those transactions into one consolidated e-invoice, submitted within seven calendar days after the month end.
The same guideline lists submission limits: 5MB per submission, 100 e-invoices per submission and 300KB per e-invoice, and allows a supplier to split a large consolidation into several. It also says consolidation does not apply to self-billed e-invoices except in listed circumstances.
For a shop or restaurant, this means a monthly job that gathers receipts, groups them correctly and submits them on time. It deserves its own tests and its own alert when it fails.
Step seven: test in the sandbox
The FAQ gives the sandbox Invoicing Portal address as preprod.myinvois.hasil.gov.my. Test with the credentials and certificate path you will use in production, using version 1.1 documents. At minimum, run these cases: a valid invoice, an invalid TIN, an old date, a duplicate, a credit note against an earlier invoice, and a consolidation near the size limits.
What a middleware layer does
A middleware layer sits between your business systems and MyInvois. Instead of each POS, ERP and shop implementing authentication, signing, submission and polling, they call one internal API. The middleware then:
- holds the credentials and the signing key in one place;
- builds and signs the document;
- submits it and polls for the result;
- records status, so the business system can show it to staff;
- runs the monthly consolidation.
The gain is one place to fix when LHDN changes something. The cost is one more service to host, monitor and secure.
A worked example: our open-source gateway
KLCube built the MyInvois Middleware Gateway on this pattern and published it as open source under the MIT licence. It is a REST API in front of MyInvois that handles the sign-in tokens, digital signing, submission and status polling, with consolidated, B2B and B2C submissions and drafts. It has SDKs for TypeScript, Python, Java and C#, and supports multi-company accounts.
It is unofficial. It is not an LHDN product, LHDN has not endorsed it, and KLCube holds no appointment or certification in connection with it. Because the code is public, a company’s own IT team can read it, run it and judge it before deciding to use it, or to build its own.
What to ask before you commission
- Which document types do we issue, and which of our systems issue them?
- Where will the signing key live, and who can use it?
- Who monitors rejected documents, and how fast?
- How is the monthly consolidation produced and checked?
- What happens to invoices when MyInvois is unreachable?
If you want a second opinion on the answers, send a written brief and we will reply with a plan.