.NET C# • MyInvois • LHDN e-Invoice API

MyInvois API Integration in .NET C#

.NET MyInvois API integration enables ASP.NET Core, C# ERP, POS and accounting applications in Malaysia to send e-Invoice data through the MySyncTax REST API. This developer guide uses HttpClient and JSON to show the core integration flow: load MySyncTax credentials securely, build the invoice payload, submit it to the documented endpoint and process the returned status, UUID and QR information. It also covers practical error handling for malformed requests, unauthorized credentials and duplicate submissions. The same pattern can be placed inside an ASP.NET Core service layer so controllers and business logic remain clean. The examples are intended as a maintainable C# MyInvois API reference that follows the live MySyncTax documentation and avoids unnecessary keyword repetition.

For developers building .NET, ASP.NET Core, ERP, POS and backend services that need MyInvois connectivity.
MyInvoisClient.cs
using var client = new HttpClient();



var json = JsonConvert.SerializeObject(payload);



var content = new StringContent(

    json,

    Encoding.UTF8,

    "application/json"

);



var response = await client.PostAsync(

    "https://mysynctax.com/v5/api/myinvois",

    content

);



var result =

    await response.Content.ReadAsStringAsync();

What Is MyInvois API Integration in .NET C#?

MyInvois API integration in .NET C# means connecting your C# business application to an e-Invoice API so invoice data can be sent as JSON, processed and returned with integration status information. MySyncTax provides an API layer designed for POS, ERP and third-party systems.

01 • C# Application

Your .NET System

Prepare invoice, customer and item data from your ASP.NET Core, desktop, ERP, POS or backend application.

02 • REST API

MySyncTax API

Send the payload as JSON over HTTPS with your assigned mysynctax_key and mysynctax_secret.

03 • MyInvois

e-Invoice Workflow

Process invoice submissions and use the returned identifiers and status information inside your own application workflow.

ASP.NET Core HttpClient MyInvois API Setup

Before coding the integration, prepare the credentials, application components and invoice data your C# service will send to the API.

Recommended .NET Components

  • .NET 6, .NET 7, .NET 8 or a compatible .NET runtime
  • HttpClient for HTTPS requests
  • Newtonsoft.Json or System.Text.Json for serialization
  • Async/await for non-blocking API calls
  • Structured logging for API request and response diagnostics

API Credentials & Payload Data

  • mysynctax_key
  • mysynctax_secret
  • External invoice number
  • Transaction or sale integration ID
  • Payment term, invoice items and amounts
  • Customer data when using ERP invoice endpoints
Keep API credentials on the server side. For ASP.NET Core applications, use configuration providers, environment variables, user secrets during development, or a managed secret store rather than hard-coding production credentials into source code.

How to Integrate MyInvois API with .NET C#

A practical implementation flow for a C# application using the documented MySyncTax API.

Configure your MySyncTax credentials

Store the assigned API key and secret securely and load them into your application configuration.

Build the invoice payload

Create a C# request object containing your integration credentials, invoice number, sale ID, payment term and invoice items.

Serialize the C# object to JSON

Use Newtonsoft.Json or System.Text.Json so the request body matches the API's expected JSON structure.

POST the request using HttpClient

Send the JSON to the appropriate MySyncTax endpoint using an HTTPS POST request with application/json.

Read and validate the API response

Check the HTTP status code and deserialize the response. Store the returned MySyncTax identifier and relevant status information with your original transaction.

Handle retry and duplicate protection

Do not blindly resend the same payload. Treat duplicate, authentication and validation responses as separate application states.

C# MyInvois API Example

The official MySyncTax documentation includes a C# HttpClient example. The example below expands that pattern into a more complete reusable integration method.

MyInvoisService.cs ASP.NET Core / .NET
using System;

using System.Threading;

using System.Threading.Tasks;

using Microsoft.Extensions.Configuration;

using System.Net;

using System.Net.Http;

using System.Text;

using Newtonsoft.Json;



public sealed class MyInvoisService

{

    private readonly HttpClient _httpClient;

    private readonly string _apiKey;

    private readonly string _apiSecret;



    public MyInvoisService(

        HttpClient httpClient,

        IConfiguration configuration)

    {

        _httpClient = httpClient;

        _apiKey = configuration["MySyncTax:ApiKey"]

            ?? throw new InvalidOperationException("Missing MySyncTax API key.");



        _apiSecret = configuration["MySyncTax:ApiSecret"]

            ?? throw new InvalidOperationException("Missing MySyncTax API secret.");

    }



    public async Task<string> SubmitInvoiceAsync(

        string invoiceNo,

        int saleId,

        CancellationToken cancellationToken = default)

    {

        var payload = new

        {

            mysynctax_key = _apiKey,

            mysynctax_secret = _apiSecret,

            invoice_no = invoiceNo,

            sale_id_integrate = saleId,

            payment_note_term = "CASH",

            items = new[]

            {

                new

                {

                    item_id = 101,

                    sorting_id = 1,

                    invoiced_quantity = 2,

                    unit_price = 30.00m,

                    item_description = "USB Keyboard",

                    price_discount = 5.00m,

                    tax_amount = 3.60m

                }

            }

        };



        var json = JsonConvert.SerializeObject(payload);



        using var content = new StringContent(

            json,

            Encoding.UTF8,

            "application/json"

        );



        using var response = await _httpClient.PostAsync(

            "https://mysynctax.com/v5/api/myinvois",

            content,

            cancellationToken

        );



        var responseBody =

            await response.Content.ReadAsStringAsync(cancellationToken);



        if (response.StatusCode == HttpStatusCode.Unauthorized)

        {

            throw new InvalidOperationException(

                "MySyncTax authentication failed."

            );

        }



        if (response.StatusCode == HttpStatusCode.Conflict)

        {

            // The same invoice payload may already exist.

            return responseBody;

        }



        response.EnsureSuccessStatusCode();



        return responseBody;

    }

}
Production tip: register HttpClient with IHttpClientFactory in ASP.NET Core rather than repeatedly creating new clients per request.

C# JSON Payload Structure

The documented normal invoice flow uses invoice-level fields plus an item collection. Keep amounts numeric and use the required date format when a date field is included.

Request JSONPOST /v5/api/myinvois
{

  "mysynctax_key": "YOUR_KEY",

  "mysynctax_secret": "YOUR_SECRET",

  "invoice_no": "INV-10001",

  "sale_id_integrate": 10001,

  "payment_note_term": "CASH",

  "items": [

    {

      "item_id": 101,

      "sorting_id": 1,

      "invoiced_quantity": 2,

      "unit_price": 30.00,

      "item_description": "USB Keyboard",

      "price_discount": 5.00,

      "tax_amount": 3.60

    }

  ]

}

Important API Formatting Rules

  • Send the body as valid JSON.
  • Include both integration credential fields.
  • Use numerical JSON values for amounts.
  • Use YYYY-MM-DD HH:MM:SS for documented date fields.
  • Keep a stable external sale or transaction ID for traceability.
  • Validate item values before sending the request.

Useful MySyncTax MyInvois API Endpoints for .NET Developers

Choose the endpoint based on the business flow your C# application needs to support.

Use case Method Endpoint
Normal invoice POST https://mysynctax.com/v5/api/myinvois
ERP invoice with customer POST https://mysynctax.com/v5/api/myinvois/invoice
Credit / Debit / Refund note POST https://mysynctax.com/v5/api/myinvois/note
Self-billed invoice POST https://mysynctax.com/v5/api/myinvois/selfbill/invoice
Self-billed note POST https://mysynctax.com/v5/api/myinvois/selfbill/note
Add / update customer POST https://mysynctax.com/v5/api/myinvois/add_customer
Add / update supplier POST https://mysynctax.com/v5/api/myinvois/add_supplier
Always verify endpoint requirements against the current MySyncTax developer documentation before deploying changes to production.

C# 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.

.NET UUID Response and MyInvois API Error Handling

Good integration code should treat each HTTP response as an application state rather than only checking whether a request returned JSON.

HTTP 400 — Invalid Request

Inspect the serialized request, required fields, JSON syntax and data types before retrying.

HTTP 401 — Unauthorized

Check the configured mysynctax_key and mysynctax_secret.

HTTP 409 — Duplicate

Do not automatically create another invoice. Reconcile the response with your existing transaction record.

HTTP 500 — Server Processing Error

Log the response, use controlled retry logic where appropriate, and avoid generating duplicate business transactions.

Recommended .NET C# Integration Architecture

Keep the MyInvois API connection behind a service layer so your accounting, POS or ERP code is not tightly coupled to raw HTTP calls.

Domain / ERP Layer

Owns the invoice, customer, supplier and transaction data used by your business application.

MyInvois Integration Service

Maps your internal models to API payloads, performs validation, submits requests and interprets responses.

Persistence & Audit

Stores the original sale ID, outbound request reference, returned UUID/status and error information for traceability.

.NET C# MyInvois Integration Best Practices

Application Reliability

  • Use typed request and response models instead of anonymous objects in larger projects.
  • Validate required invoice fields before making an API call.
  • Use cancellation tokens and sensible HTTP timeouts.
  • Log request IDs and transaction IDs, but avoid logging secrets.
  • Handle duplicate submissions as an idempotency concern.

Security & Operations

  • Never expose the API secret in browser-side JavaScript.
  • Use HTTPS endpoints only.
  • Separate sandbox/test configuration from production credentials.
  • Restrict access to integration logs containing customer or invoice data.
  • Review API documentation before production releases.

Delete Invoice

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.

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"

}

C# HttpClient example

Keep the credentials in server-side environment configuration. This example assumes httpClient is a reused HttpClient instance.

using System;

using System.Collections.Generic;

using System.Net.Http;

using System.Text;

using System.Text.Json;



var mysynctax_uniqueId = "YOUR_INVOICE_UNIQUE_ID";

var url = $"https://mysynctax.com/v5/api/myinvois/delete/{Uri.EscapeDataString(mysynctax_uniqueId)}";

var payload = new Dictionary<string, string>

{

    ["mysynctax_key"] = Environment.GetEnvironmentVariable("MYSYNCTAX_KEY")

        ?? throw new InvalidOperationException("MYSYNCTAX_KEY is not configured."),

    ["mysynctax_secret"] = Environment.GetEnvironmentVariable("MYSYNCTAX_SECRET")

        ?? throw new InvalidOperationException("MYSYNCTAX_SECRET is not configured.")

};



using var content = new StringContent(

    JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");

using var response = await httpClient.PostAsync(url, content);

var responseBody = await response.Content.ReadAsStringAsync();

response.EnsureSuccessStatusCode();

Console.WriteLine(responseBody);

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.

MyInvois API Integration .NET C# FAQ

Common implementation questions from developers integrating Malaysian e-Invoice workflows into C# applications.

Can I integrate MyInvois with a .NET C# application?

Yes. A C# application can send JSON requests to the MySyncTax API using HttpClient and process the JSON response returned by the endpoint.

Which credentials are required for the API?

MySyncTax integration requests require mysynctax_key and mysynctax_secret in the JSON request body.

What is the standard invoice endpoint?

The documented standard submission endpoint is POST https://mysynctax.com/v5/api/myinvois.

Should I use Newtonsoft.Json or System.Text.Json?

Either can be used in a .NET application as long as the resulting JSON matches the API's expected field names and data types. The official documentation currently shows a Newtonsoft.Json example.

How should I handle HTTP 409 in C#?

Treat it as a duplicate-submission state. Reconcile the returned information against the original invoice instead of blindly creating or resending a new transaction.

Can ASP.NET Core use IHttpClientFactory for this integration?

Yes. In an ASP.NET Core project, a typed or named HttpClient registered through IHttpClientFactory is a clean way to manage the API client.

Is there a separate ASP.NET Core MyInvois sandbox or production API?

The current MySyncTax developer documentation does not list separate ASP.NET Core-specific sandbox and production endpoints. Your C# application uses the documented REST endpoints, while environment access and credentials should be confirmed with MySyncTax before going live.

Need to connect your .NET system to MyInvois?

Use the MySyncTax developer documentation for the current API payloads and endpoints, or contact the integration team if you need help mapping your ERP, POS or accounting data into the MyInvois workflow.