Laravel
Laravel HTTP client, configuration and service-layer examples.
Laravel MyInvois API integration lets Malaysian businesses connect a Laravel application, ERP, POS or accounting workflow to LHDN e-Invoice services through the MySyncTax REST API. This guide focuses on a practical server-side implementation using Laravel's HTTP client, protected API credentials, structured JSON requests and clear response handling. You will see how to authenticate with MySyncTax, submit invoice data, store the returned UUID or QR information, handle HTTP errors such as 401 and 409, and extend the same integration pattern to ERP customer invoices and related e-Invoice workflows. The examples are written for developers who want a maintainable Laravel integration without repeating keywords unnaturally or exposing production credentials in application code.
// Laravel → MySyncTax → LHDN MyInvois
$response = Http::acceptJson()
->asJson()
->post(
config('services.mysynctax.url')
. '/v5/api/myinvois',
[
'mysynctax_key' => config(
'services.mysynctax.key'
),
'mysynctax_secret' => config(
'services.mysynctax.secret'
),
'invoice_no' => 'INV-1001',
'sale_id_integrate' => 1001,
'payment_note_term' => 'CASH',
'items' => $items,
]
);
A Laravel MyInvois integration connects your application, ERP, POS, accounting platform or custom business system to an e-Invoice API. With MySyncTax, Laravel sends structured JSON to MySyncTax and receives submission results that can be stored back in your application.
mysynctax_key and mysynctax_secret in the JSON body. The standard invoice endpoint shown in the documentation is POST https://mysynctax.com/v5/api/myinvois. Keep the integration server-side and separate credentials from your application source code.
A Laravel project that can make outbound HTTPS requests using Laravel's HTTP client.
Your assigned mysynctax_key and mysynctax_secret. Keep both values private.
Invoice number, internal sale ID, payment term and item-level information formatted as JSON.
Plan database fields for the MySyncTax UUID, QR URL, submission status and any returned LHDN identifiers.
mysynctax_secret in JavaScript, a public Git repository, HTML, or a mobile app bundle. Keep the MyInvois integration on your Laravel backend. The examples below use Laravel's built-in HTTP client so you do not need a separate HTTP package for the basic integration.
.envKeep the base URL and credentials outside your application code.
MYSYNCTAX_BASE_URL=https://mysynctax.com
MYSYNCTAX_KEY=your_mysynctax_key
MYSYNCTAX_SECRET=your_mysynctax_secret
config/services.phpUsing Laravel config keeps your service class clean and lets you use normal configuration caching in production.
'mysynctax' => [
'url' => env('MYSYNCTAX_BASE_URL', 'https://mysynctax.com'),
'key' => env('MYSYNCTAX_KEY'),
'secret' => env('MYSYNCTAX_SECRET'),
],
Centralizing API calls in a service class makes it easier to reuse the same integration in controllers, jobs and scheduled processes.
<?php
namespace App\Services;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
class MySyncTaxService
{
private string $baseUrl;
private string $key;
private string $secret;
public function __construct()
{
$this->baseUrl = rtrim(config('services.mysynctax.url'), '/');
$this->key = (string) config('services.mysynctax.key');
$this->secret = (string) config('services.mysynctax.secret');
}
public function submitInvoice(array $invoice): Response
{
return Http::acceptJson()
->asJson()
->timeout(30)
->post($this->baseUrl . '/v5/api/myinvois', [
'mysynctax_key' => $this->key,
'mysynctax_secret' => $this->secret,
...$invoice,
]);
}
public function submitErpInvoice(array $invoice): Response
{
return Http::acceptJson()
->asJson()
->timeout(30)
->post($this->baseUrl . '/v5/api/myinvois/invoice', [
'mysynctax_key' => $this->key,
'mysynctax_secret' => $this->secret,
...$invoice,
]);
}
}
This is the MySyncTax normal invoice request body. Replace the sample transaction and credential values with your server-side data. Send it to POST https://mysynctax.com/v5/api/myinvois.
{
"mysynctax_key": "YOUR_API_KEY",
"mysynctax_secret": "YOUR_API_SECRET",
"invoice_no": "INV-1001",
"sale_id_integrate": 1001,
"payment_note_term": "CASH",
"items": [
{
"item_id": 101,
"sorting_id": 1,
"invoiced_quantity": 2,
"unit_price": 30.0,
"item_description": "USB Keyboard",
"price_discount": 0,
"tax_amount": 3.6
}
]
}
See the MySyncTax developer documentation for the endpoint contract. Direct LHDN submissions use a different document structure.
For the normal invoice with receipt QR flow, MySyncTax documents POST https://mysynctax.com/v5/api/myinvois. The JSON includes your credentials plus invoice and item data.
$payload = [
'invoice_no' => 'INV-1001',
'sale_id_integrate' => 1001,
'payment_note_term' => 'CASH',
'items' => [
[
'item_id' => 12,
'sorting_id' => 1,
'invoiced_quantity' => 2,
'unit_price' => 60.00,
'item_description' => 'Premium Nasi Ayam Set',
'price_discount' => 20,
'tax_amount' => 10.00,
],
[
'item_id' => 13,
'sorting_id' => 2,
'invoiced_quantity' => 1,
'unit_price' => 90.00,
'item_description' => 'Iced Coffee Latte',
'price_discount' => 10,
'tax_amount' => 8.00,
],
],
];
$response = app(\App\Services\MySyncTaxService::class)
->submitInvoice($payload);
if ($response->successful()) {
$data = $response->json();
$invoice->update([
'mysynctax_uuid' => $data['mysynctax_uuid'] ?? null,
'mysynctax_qr_url' => $data['qr_url'] ?? null,
'mysynctax_status' => $data['status'] ?? null,
]);
return response()->json([
'message' => 'Invoice submitted',
'data' => $data,
]);
}
The standard success example in the MySyncTax documentation returns status, mysynctax_uuid and qr_url.
YYYY-MM-DD HH:MM:SS. MySyncTax also documents duplicate payload detection using HTTP 409. For ERP or accounting systems that manage customer master data, MySyncTax documents a dedicated invoice endpoint. This request can include customer TIN, registration name, identification details and address information.
$payload = [
'isAutoToLHDN' => 1,
'invoice_no' => 'INV-322',
'sale_id_integrate' => 3312,
'payment_note_term' => 'CASH',
'customer' => [
'tin_no' => 'IG25461820000',
'registration_name' => 'ABC Trading Sdn Bhd',
'identification_no' => '930105045119',
'identification_type' => 'NRIC',
'sst_registration' => 'SST123456',
'phone' => '0123456789',
'email' => 'finance@abctrading.com',
'address_line_1' => 'No 10, Jalan Teknologi',
'address_line_2' => 'Taman Teknologi',
'address_line_3' => 'Seksyen 7',
'city_name' => 'Shah Alam',
'postal_zone' => '40000',
'state_code' => '10',
'country_code' => 'MYS',
],
'items' => [
[
'item_id' => 101,
'sorting_id' => 1,
'item_description' => 'USB Keyboard',
'invoiced_quantity' => 2,
'unit_price' => 30.00,
'price_discount' => 5,
'tax_amount' => 3.60,
],
],
];
$response = app(\App\Services\MySyncTaxService::class)
->submitErpInvoice($payload);
$data = $response->json();
invoice_id, mysynctax_uuid, customer_status, qr_lhdn, customer_id, a submission UID and accepted or rejected document information. Illustrative normal invoice response from the MySyncTax API documentation; identifiers and the receipt URL below are placeholders.
{
"status": "ok",
"mysynctax_uuid": "generated-unique-id",
"qr_url": "https://mysynctax.com/v5/redirect/EXAMPLE"
}
Save the MySyncTax UUID against your local invoice. This receipt response alone does not establish that LHDN has validated an e-Invoice. Handle HTTP errors and the returned status before updating your records.
Do not treat every non-200 response as the same problem. Separate authentication, duplicate, validation and server failures in your Laravel workflow.
$response = $mySyncTax->submitInvoice($payload);
if ($response->successful()) {
return $response->json();
}
if ($response->status() === 401) {
throw new \RuntimeException('Invalid MySyncTax API credentials.');
}
if ($response->status() === 409) {
$duplicate = $response->json();
// Handle duplicate separately instead of blindly retrying.
return $duplicate;
}
if ($response->status() === 400) {
throw new \InvalidArgumentException(
$response->json('message') ?? 'Invalid invoice payload.'
);
}
$response->throw();
These status codes are documented by MySyncTax for the main invoice flow and related note operations.
| HTTP | Documented meaning | Recommended Laravel handling |
|---|---|---|
| 400 | Invalid or malformed JSON | Log the request context, validate your payload and return a controlled validation error. |
| 401 | API key or secret missing / invalid | Stop retries and verify MYSYNCTAX_KEY and MYSYNCTAX_SECRET. |
| 404 | Invoice UUID not found for applicable note flows | Check the stored UUID before sending a credit, debit or refund operation. |
| 409 | Duplicate invoice / duplicate submission | Do not create another local invoice. Inspect the duplicate response and reconcile using the stored sale ID / UUID. |
| 422 | Item mismatch for applicable note flows | Validate note items against the original invoice before resubmitting. |
| 500 | Server processing error | Log the failure and use a controlled queue / retry policy instead of immediate repeated requests. |
401, malformed 400 payloads, or known duplicates as though they were transient network failures. Reserve automatic retries for failures that can realistically succeed later. The API call is only one part of a production e-Invoice integration. Your Laravel application should also protect credentials, record external IDs and make failures traceable.
sale_id_integrate stable.mysynctax_uuid after submission.The same Laravel service pattern can be extended to additional endpoints documented by MySyncTax.
Submit adjustment notes for invoices already submitted to LHDN. The payload uses a documented note_type such as credit, debit or refund.
For cases where the buyer generates the e-Invoice on behalf of the supplier.
Create or update customer master data before relevant ERP or invoice workflows.
Maintain supplier information for self-billed and ERP-related invoice scenarios.
Use the returned mysynctax_uuid to retrieve the rendered e-Invoice PDF according to the developer documentation.
The documentation states that LHDN enforces a 72-hour cancellation window. Your Laravel UI should therefore expose cancellation carefully.
Trigger an email notification containing the PDF e-Invoice link using the documented UUID input.
Use the documented general TIN workflow for applicable scenarios such as walk-in / B2C or other defined cases.
The developer documentation remains the source of truth for current endpoint fields, examples and response formats.
The API documentation provides a PDF URL based on the returned MySyncTax UUID.
use App\Models\Invoice;
Route::get('/invoices/{invoice}/pdf', function (Invoice $invoice) {
abort_unless($invoice->mysynctax_uuid, 404);
$url = 'https://mysynctax.com/v5/invoice/view/'
. urlencode($invoice->mysynctax_uuid);
return redirect()->away($url);
});
Use this API to request deletion of an invoice from MySyncTax by its unique ID. The API validates your integration credentials and checks the invoice submission status before processing the request.
POST https://mysynctax.com/v5/api/myinvois/delete/{mysynctax_uniqueId}
mysynctax_unique_id (string): unique invoice identifier passed in the URL.mysynctax_key (string): integration API key assigned to your company.mysynctax_secret (string): integration API secret assigned to your company.Send both integration credentials in the JSON request body.
{
"mysynctax_key": "YOUR_MYSYNCTAX_KEY",
"mysynctax_secret": "YOUR_MYSYNCTAX_SECRET"
}
Store the credentials in server-side configuration, for example services.mysynctax.key and services.mysynctax.secret.
use Illuminate\Support\Facades\Http;
$mysycntax_uniqueId = 'YOUR_INVOICE_UNIQUE_ID';
$url = 'https://mysynctax.com/v5/api/myinvois/delete/' . rawurlencode($mysycntax_uniqueId);
$response = Http::acceptJson()
->timeout(30)
->post($url, [
'mysynctax_key' => config('services.mysynctax.key'),
'mysynctax_secret' => config('services.mysynctax.secret'),
]);
$response->throw();
$result = $response->json();
if (!($result['success'] ?? false)) {
// Inspect the API message; an already-submitted invoice cannot be deleted.
logger()->warning('Invoice deletion was not completed', $result);
}
This response indicates that deletion was rejected because the invoice has already been submitted to LHDN.
{
"success": false,
"message": "Invoice cannot be deleted because it has already been submitted.",
"unique_id": "50dc9929XXXXXXXXXXXXXXXXXXXXXXXXXX",
"invoice_no": "MZXXX-XXXXXXXX",
"submission_status": "Submitted"
}
The response includes success (boolean), message, unique_id, invoice_no and submission_status.
Important: Use POST, pass the invoice unique ID in the URL, and include both credentials in the JSON body. An invoice already submitted to LHDN cannot be deleted through this API. The supplied URL contains /dev/; confirm that this is the correct base path for your environment.
Common implementation questions for Laravel developers integrating Malaysian e-Invoice workflows.
Yes. Laravel can send JSON over HTTPS using its built-in HTTP client. This guide uses a small service class so invoice submission logic stays outside controllers.
Store them in server-side environment configuration such as .env and expose them to your service through config/services.php. Do not place the secret in frontend JavaScript or public source code.
The developer documentation lists POST https://mysynctax.com/v5/api/myinvois for the normal invoice with receipt QR flow.
MySyncTax documents POST https://mysynctax.com/v5/api/myinvois/invoice for ERP and accounting systems that manage customer data and require direct submission flow.
The main API documentation maps duplicates to HTTP 409. Handle that response separately, reconcile the existing transaction, and do not blindly retry the same payload.
At minimum, keep the returned MySyncTax UUID and relevant submission status. Depending on the endpoint, you may also receive a QR URL, LHDN QR link, invoice ID, customer information, submission UID and accepted document UUID.
Yes. The developer documentation lists GET https://mysynctax.com/v5/invoice/view/{mysynctax_uuid}. You can redirect an authorized Laravel user to that URL or incorporate it into your document workflow.
Yes. The developer documentation includes a note endpoint and supports the documented credit, debit and refund note types.
The current MySyncTax developer documentation does not list a separate Laravel-specific sandbox endpoint. Use the environment and credentials issued for your integration, and confirm test-versus-production access with MySyncTax before sending live invoice data.
Share your Laravel application type, invoice flow, customer volume and whether you need normal invoice, ERP, self-billed or note workflows. MySyncTax can help you map your existing data structure to the available API endpoints.
Use WhatsApp for integration enquiries and implementation discussions.