PHP REST API • MyInvois • Malaysia e-Invoice

MyInvois API Integration in PHP

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.

● Use placeholder credentials while developing. Keep production API secrets outside public source code.
myinvois-integration.php
<?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);
Developer Overview

What Is MyInvois API Integration in PHP?

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.

₱

PHP Application

Your POS, ERP, accounting system or custom PHP platform remains responsible for its own business transaction data and application workflow.

API

MySyncTax REST API

PHP sends JSON requests over HTTPS using cURL, Laravel HTTP Client, Guzzle or another HTTP client that supports REST APIs.

✓

e-Invoice Response

Your application reads the JSON response and records the relevant status, identifiers, QR information or error details for its own workflow.

Related Developer Guides

Use the guide that matches your application framework or language. These links connect each implementation guide while keeping this page focused on PHP.

Integration Flow

How PHP Connects to the MyInvois e-Invoice Workflow

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.

Prepare invoice data

Collect the invoice number, transaction reference, payment term, item lines and any customer or supplier details required by your selected API flow.

→

Create JSON payload

Use PHP arrays and json_encode() to build a valid request body with your MySyncTax credentials.

→

POST over HTTPS

Send the JSON request using PHP cURL or your preferred server-side HTTP client and capture the HTTP response code.

→

Process response

Decode the returned JSON, store the integration result and route failures into application logs or a controlled retry process.

Before You Code

PHP Integration Requirements

A standard server-side PHP environment is enough for the basic REST integration pattern.

PHP Environment

  • Server-side PHP application
  • HTTPS outbound connectivity
  • JSON support enabled

HTTP Client

  • PHP cURL extension
  • Laravel HTTP Client
  • Guzzle or equivalent

API Access

  • MySyncTax API key
  • MySyncTax API secret
  • Correct API endpoint

Application Logic

  • Unique invoice references
  • Secure logging
  • HTTP error handling
Authentication

MyInvois API Authentication in PHP

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.

Recommended environment variables

.env example
MYSYNCTAX_KEY=your_api_key



MYSYNCTAX_SECRET=your_api_secret

Read credentials in PHP

credentials.php
$apiKey = getenv('MYSYNCTAX_KEY');



$apiSecret = getenv('MYSYNCTAX_SECRET');







if (!$apiKey || !$apiSecret) {



    throw new RuntimeException(



        'API credentials are not configured.'



    );



}
Authentication handling: treat an HTTP 401 response as a credential or authorization problem. Do not continuously retry an authentication failure without correcting the configuration.

PHP MyInvois API Request JSON Example

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.

PHP cURL Example

PHP cURL MyInvois Integration Example

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.

POST https://mysynctax.com/v5/api/myinvois
myinvois-integration.php
<?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}"



    );



}

1. Build the payload

Use a PHP associative array so your application can map transaction and item data into a clear JSON request.

2. Send JSON

Set the request content type to application/json, send the payload with POST and retain the HTTP status code.

3. Store the result

Decode the response, record the submission result and avoid exposing credentials or sensitive payload data in public logs.

PHP MySyncTax JSON Response Example

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.

Response Handling

MyInvois UUID Response and Error Handling in PHP

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.

Example response handling

response-handler.php
$data = json_decode($responseBody, true);







if ($httpCode === 200) {



    $uuid = $data['mysynctax_uuid'] ?? null;



    $qr   = $data['qr_url'] ?? null;







    // Save result against local invoice.



}

What your application should store

  • Your local invoice or transaction ID
  • API submission status
  • Returned integration UUID when available
  • Relevant QR or e-Invoice reference data
  • Timestamp and safe error context
API Scenarios

MyInvois PHP Integration Options

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.

Normal Invoice

Invoice + Receipt QR

Suitable for a standard transaction flow where your application sends invoice header and item information through the main integration endpoint.

POST/v5/api/myinvois
ERP / Accounting

Invoice With Customer

Use the ERP/customer flow when your system manages customer master data and needs to include customer details with the invoice request.

POST/v5/api/myinvois/invoice
Adjustments

Credit, Debit & Refund Notes

Use an adjustment workflow for transactions that relate back to an invoice already processed through the e-Invoice workflow.

POST/v5/api/myinvois/note
Self-Billed

Self-Billed Invoice

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.

POST/v5/api/myinvois/selfbill/invoice
Master Data

Add or Update Customers

ERP and POS systems can maintain customer master information through a dedicated API flow before related invoice processing.

POST/v5/api/myinvois/add_customer
Master Data

Add or Update Suppliers

Supplier master data can be maintained separately for workflows such as self-billed invoices and other supplier-driven transactions.

POST/v5/api/myinvois/add_supplier
Endpoint availability and required fields can change as the integration evolves. Always verify the current request structure in the live MySyncTax Developer Documentation before deploying production code.
ERP Pattern

Send e-Invoice to LHDN Using PHP

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 mapping example

customer-map.php
$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'



];

Keep transport reusable

api-client.php
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.

Reliability

Handle MyInvois API Errors in PHP

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.
PHP Best Practices

Security and Reliability for MyInvois API Integration PHP

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.

🔐

Protect API secrets

Keep credentials in environment configuration or a secret store. Never place production keys in browser-side JavaScript, public Git repositories or HTML source.

🧾

Use stable references

Maintain a clear link between your local transaction ID and the API submission result so support staff can trace each integration event.

↻

Control retries

Retry only errors that can reasonably succeed later. Avoid automatically resending authentication, validation or duplicate failures.

⏱

Set timeouts

Configure connection and request timeouts so a temporary network issue does not leave a PHP request running indefinitely.

🧪

Test before production

Validate mapping, numerical values, identifiers and application error handling with test data before enabling automated production submission.

📋

Log safely

Record enough context for troubleshooting but redact API credentials and minimize unnecessary storage of sensitive customer information.

Deployment Checklist

Before Going Live

Use a repeatable deployment checklist instead of treating the integration as a single successful API call.

Application checks

  • Credentials come from protected configuration.
  • Invoice references remain unique and traceable.
  • All amounts are sent as numeric values.
  • Customer or supplier fields are mapped consistently.
  • The PHP application stores the API result safely.

Failure checks

  • 401 responses stop and alert configuration owners.
  • Duplicate responses do not create duplicate invoices locally.
  • Validation errors are visible to support users.
  • Server failures use limited, controlled retry logic.
  • Logs redact API secrets and sensitive information.
Trust & Technical References

How This PHP Integration Guide Is Maintained

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.

Page information

PublisherMySyncTax
Content typeTechnical developer integration guide
Last updated25 September 2026

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.

Related MyInvois resources

Continue with these MySyncTax resources for broader implementation planning.

Delete Invoice

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.

Endpoint

POST https://mysynctax.com/v5/api/myinvois/delete/{mysynctax_uniqueId}

Request parameters

  • 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.

Request example

Send both integration credentials in the JSON request body.

{

  "mysynctax_key": "YOUR_MYSYNCTAX_KEY",

  "mysynctax_secret": "YOUR_MYSYNCTAX_SECRET"

}

PHP cURL example

          $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);

Response example

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.

Frequently Asked Questions

MyInvois API Integration PHP FAQ

Common questions from PHP developers, software vendors and ERP teams planning a MyInvois integration.

Can PHP integrate with MyInvois e-Invoice?

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.

How does MyInvois API Integration PHP work with MySyncTax?

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.

Do I need Laravel for MyInvois API integration?

No. Standard PHP with cURL is enough for the HTTP integration. If your application uses Laravel, follow the dedicated Laravel integration guide.

Where should I store the MySyncTax API key and secret?

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.

How should PHP handle duplicate invoice submissions?

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.

Can the same PHP integration support ERP customer invoices and self-billed invoices?

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.

Can MySyncTax be integrated with an existing PHP POS system?

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.

Where can I see the latest MySyncTax request fields and endpoints?

Use the live MySyncTax Developer Documentation as the source for the latest endpoint and payload requirements before deploying or updating production integration code.

Is there a separate MyInvois sandbox and production endpoint for PHP?

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.

Start Building

Build Your MyInvois API Integration in PHP

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