PHP Application
Your POS, ERP, accounting system or custom PHP platform remains responsible for its own business transaction data and application workflow.
PHP MyInvois API integration allows a Malaysian business system to send e-Invoice data from a PHP application to LHDN workflows through the MySyncTax REST API. This guide uses standard PHP and cURL so the implementation can work in custom PHP systems without requiring Laravel. It covers MySyncTax authentication, JSON request construction, invoice submission, UUID and status responses, duplicate handling and common HTTP errors. The examples keep API credentials on the server and show a straightforward pattern that can be adapted for ERP, POS and accounting applications. For developers searching for a practical PHP cURL MyInvois integration, the focus here is on readable code, predictable error handling and the documented MySyncTax endpoints rather than keyword-heavy marketing copy.
<?php
$endpoint = 'https://mysynctax.com/v5/api/myinvois';
$payload = [
'mysynctax_key' => getenv('MYSYNCTAX_KEY'),
'mysynctax_secret' => getenv('MYSYNCTAX_SECRET'),
'invoice_no' => 'INV-1001',
'sale_id_integrate' => 1001,
'payment_note_term' => 'CASH',
'items' => [/\* invoice items \*/]
];
$ch = curl_init($endpoint);
MyInvois API integration in PHP is the process of connecting a PHP-based business application to an e-Invoice integration service over HTTPS. Your application prepares invoice data as JSON, sends it to the API, and processes the returned submission status, identifiers and related response data.
Your POS, ERP, accounting system or custom PHP platform remains responsible for its own business transaction data and application workflow.
PHP sends JSON requests over HTTPS using cURL, Laravel HTTP Client, Guzzle or another HTTP client that supports REST APIs.
Your application reads the JSON response and records the relevant status, identifiers, QR information or error details for its own workflow.
Use the guide that matches your application framework or language. These links connect each implementation guide while keeping this page focused on PHP.
Standard PHP and cURL implementation.
Laravel HTTP client and configuration patterns.
C# implementation for .NET business applications.
VB.NET guide for existing enterprise systems.
Keep the integration modular: build the invoice in your PHP system, send it through the appropriate MySyncTax endpoint, then update your local transaction record from the API response.
Collect the invoice number, transaction reference, payment term, item lines and any customer or supplier details required by your selected API flow.
→Use PHP arrays and json_encode() to build a valid request body with your MySyncTax credentials.
→Send the JSON request using PHP cURL or your preferred server-side HTTP client and capture the HTTP response code.
→Decode the returned JSON, store the integration result and route failures into application logs or a controlled retry process.
A standard server-side PHP environment is enough for the basic REST integration pattern.
MySyncTax integration requests use two credential values in the JSON request body: mysynctax_key and mysynctax_secret. Keep both values server-side and load them from protected configuration rather than hard-coding production secrets in public repositories.
MYSYNCTAX_KEY=your_api_key
MYSYNCTAX_SECRET=your_api_secret
$apiKey = getenv('MYSYNCTAX_KEY');
$apiSecret = getenv('MYSYNCTAX_SECRET');
if (!$apiKey || !$apiSecret) {
throw new RuntimeException(
'API credentials are not configured.'
);
}
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.
The example below demonstrates a practical server-side PHP request for a normal invoice integration. Replace the placeholder values with data generated by your own POS, ERP or application and verify the current field requirements against the MySyncTax developer documentation before production deployment.
<?php
$endpoint = 'https://mysynctax.com/v5/api/myinvois';
$payload = [
'mysynctax_key' => getenv('MYSYNCTAX_KEY'),
'mysynctax_secret' => getenv('MYSYNCTAX_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.00,
'item_description' => 'USB Keyboard',
'price_discount' => 0,
'tax_amount' => 3.60
]
]
];
$json = json_encode($payload, JSON_UNESCAPED_SLASHES);
if ($json === false) {
throw new RuntimeException('Unable to encode invoice payload.');
}
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => $json
]);
$responseBody = curl_exec($ch);
if ($responseBody === false) {
$message = curl_error($ch);
curl_close($ch);
throw new RuntimeException('API connection failed: ' . $message);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$response = json_decode($responseBody, true);
if (!is_array($response)) {
throw new RuntimeException(
'The API returned an unreadable JSON response.'
);
}
if ($httpCode >= 200 && $httpCode < 300) {
// Save the relevant success data in your own database.
// Example:
$status = $response['status'] ?? null;
$uuid = $response['mysynctax_uuid'] ?? null;
echo 'Submission status: ' . ($status ?? 'unknown');
} else {
// Log safely. Do not log API secrets.
$message = $response['message'] ?? 'API request failed';
throw new RuntimeException(
"MySyncTax API error ({$httpCode}): {$message}"
);
}
Use a PHP associative array so your application can map transaction and item data into a clear JSON request.
Set the request content type to application/json, send the payload with POST and retain the HTTP status code.
Decode the response, record the submission result and avoid exposing credentials or sensitive payload data in public logs.
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.
Your integration should treat the HTTP status code and the decoded JSON body as two separate signals. A successful request can provide status information and identifiers that your system can associate with the original transaction.
$data = json_decode($responseBody, true);
if ($httpCode === 200) {
$uuid = $data['mysynctax_uuid'] ?? null;
$qr = $data['qr_url'] ?? null;
// Save result against local invoice.
}
The correct endpoint depends on the business scenario. Keep each PHP integration flow in its own service class or module so normal invoices, customer invoices and adjustment documents do not become mixed together.
Suitable for a standard transaction flow where your application sends invoice header and item information through the main integration endpoint.
Use the ERP/customer flow when your system manages customer master data and needs to include customer details with the invoice request.
Use an adjustment workflow for transactions that relate back to an invoice already processed through the e-Invoice workflow.
Use the self-billed flow when your business application needs to prepare a self-billed transaction and submit supplier information as part of the request.
ERP and POS systems can maintain customer master information through a dedicated API flow before related invoice processing.
Supplier master data can be maintained separately for workflows such as self-billed invoices and other supplier-driven transactions.
For an ERP or accounting platform, separate customer mapping from transport logic. This makes it easier to validate customer records, test the payload and reuse the same PHP HTTP function across invoice types.
$customer = [
'tin_no' => $row['tin_no'],
'registration_name' => $row['name'],
'identification_type' => $row['id_type'],
'identification_no' => $row['id_no'],
'phone' => $row['phone'],
'email' => $row['email'],
'country_code' => 'MYS'
];
function postJson($endpoint, array $payload): array
{
// Encode JSON
// Send HTTPS POST
// Capture HTTP status
// Decode JSON
// Return normalized result
}
A small API client prevents duplicate cURL code across invoice, note, customer and supplier services.
Production integrations should not treat every non-200 response the same. Separate malformed data, authentication, missing references, duplicates, validation problems and server failures so your application can choose the correct next action.
| HTTP code | Typical meaning | Recommended PHP action |
|---|---|---|
| 400 | Request data or JSON is not accepted. | Validate JSON encoding and required values before retrying. |
| 401 | Authentication credentials are missing or not accepted. | Check server-side configuration. Do not retry continuously. |
| 404 | A referenced invoice or resource may not be found in a flow that requires it. | Verify the stored reference before sending the request again. |
| 409 | The request conflicts with an existing or duplicate submission. | Check your local transaction state before creating a second submission. |
| 422 | A request can be structurally readable but fail a business or item validation rule. | Surface the validation issue to the application instead of blind retrying. |
| 500 | The server could not complete processing. | Log safely and use a controlled retry strategy with limits. |
Treat e-Invoice integration as server-to-server infrastructure. Keep secrets protected, make submissions traceable and design the integration so one temporary network problem does not create duplicate accounting transactions.
Keep credentials in environment configuration or a secret store. Never place production keys in browser-side JavaScript, public Git repositories or HTML source.
Maintain a clear link between your local transaction ID and the API submission result so support staff can trace each integration event.
Retry only errors that can reasonably succeed later. Avoid automatically resending authentication, validation or duplicate failures.
Configure connection and request timeouts so a temporary network issue does not leave a PHP request running indefinitely.
Validate mapping, numerical values, identifiers and application error handling with test data before enabling automated production submission.
Record enough context for troubleshooting but redact API credentials and minimize unnecessary storage of sensitive customer information.
Use a repeatable deployment checklist instead of treating the integration as a single successful API call.
This page is published by MySyncTax as technical implementation guidance for developers integrating PHP applications with the MySyncTax API. Production integrations should always be checked against the live developer documentation because request fields and available API routes can change.
Code examples use placeholder credentials and illustrative transaction values. Confirm the latest required fields, endpoint behavior and production requirements in the developer documentation before deployment.
Continue with these MySyncTax resources for broader implementation planning.
Request invoice deletion by its unique ID and check the document submission status.
The API validates your integration credentials and checks the invoice submission status before processing a deletion 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"
}
$mysycntax_uniqueId = 'YOUR_INVOICE_UNIQUE_ID';
$url = 'https://mysynctax.com/v5/api/myinvois/delete/' . rawurlencode($mysycntax_uniqueId);
$payload = [
'mysynctax_key' => getenv('MYSYNCTAX_KEY'),
'mysynctax_secret' => getenv('MYSYNCTAX_SECRET'),
];
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true,
]);
$responseBody = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($responseBody === false) {
throw new RuntimeException(curl_error($ch));
}
curl_close($ch);
$result = json_decode($responseBody, true);
if ($httpStatus >= 400) {
throw new RuntimeException('Delete request failed: ' . $responseBody);
}
var_dump($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 questions from PHP developers, software vendors and ERP teams planning a MyInvois integration.
Yes. PHP can send server-side HTTPS requests containing JSON and process JSON responses. MySyncTax provides API endpoints that a PHP application can call using cURL, Laravel HTTP Client, Guzzle or a similar HTTP library.
Your PHP system builds the transaction payload, includes its MySyncTax credentials, sends the data to the appropriate REST endpoint and then stores or acts on the API response.
No. Standard PHP with cURL is enough for the HTTP integration. If your application uses Laravel, follow the dedicated Laravel integration guide.
Keep credentials in server-side environment configuration or a protected secrets mechanism. Avoid hard-coding production credentials in source files that may be committed to a repository.
Keep a local integration status for each transaction and check the HTTP response before attempting another submission. A duplicate response should be handled as a state-management case rather than repeatedly retried.
Yes, but keep the flows separated in your application because they use different business data and API routes. A reusable HTTP client can be shared while each invoice type has its own payload builder and validation rules.
Yes. If the POS can prepare transaction data and make secure server-side HTTPS requests, it can implement the same REST integration pattern described in this guide.
Use the live MySyncTax Developer Documentation as the source for the latest endpoint and payload requirements before deploying or updating production integration code.
The current MySyncTax developer documentation does not identify separate PHP-specific sandbox and production endpoints. PHP uses the documented REST endpoints, while environment access and credentials should be confirmed with MySyncTax before live deployment.
Use this page as the PHP implementation guide, then confirm current payload fields and available API routes in the MySyncTax developer documentation before production deployment.
Technical reference: MySyncTax Developer Documentation