VB.NET • HttpClient • JSON • LHDN e-Invoice

MyInvois API Integration in VB.NET

Visual Basic .NET MyInvois API integration lets VB.NET WinForms, desktop ERP and business applications connect to Malaysian e-Invoice workflows through the MySyncTax REST API. This guide uses HttpClient and JSON to keep the implementation compatible with familiar .NET patterns while separating credentials from presentation code. It explains MySyncTax authentication, invoice payload construction, e-Invoice submission, UUID and QR response handling, and common API errors such as unauthorized or duplicate requests. The same approach can be wrapped in a reusable service class for existing ERP or accounting software. For teams maintaining long-lived VB.NET systems, the goal is a clear integration path that follows the documented MySyncTax API without forcing a framework migration or overusing SEO keywords.

VB.NET Application
HttpClient + JSON request
.NET
POST invoice payload
mysynctax_key + mysynctax_secret
MySyncTax API
Validate, process and return e-Invoice result
VB.NET receives JSON response
Store UUID, QR URL, status or error details
VB.NET → MySyncTax → MyInvois

What Is MyInvois API Integration in VB.NET?

MyInvois API Integration VB.NET means connecting a Visual Basic .NET application to an e-Invoice API so invoice data can be transmitted programmatically instead of being entered manually. In this implementation, your VB.NET system talks to the MySyncTax API, while MySyncTax provides the integration layer used for MyInvois-oriented e-Invoice workflows.

Step 1

Prepare Invoice Data

Build an object containing invoice identifiers, payment terms, customer or supplier data when required, and invoice items.

Step 2

Serialize to JSON

Use Newtonsoft.Json or another compatible JSON serializer to convert the VB.NET object into the JSON format expected by the API.

Step 3

POST with HttpClient

Send the JSON body over HTTPS with application/json, then read the returned JSON and store the response details.

VB.NET MyInvois API Authentication

The integration can be implemented with standard .NET HTTP and JSON components. The MySyncTax documentation requires API credentials in the request body.

Application Requirements

  • A VB.NET application capable of making HTTPS requests.
  • System.Net.Http for HttpClient.
  • System.Text for UTF-8 request content.
  • A JSON library such as Newtonsoft.Json for serialization and parsing.
  • Secure storage for API credentials outside source code.

MySyncTax Authentication

  • mysynctax_key identifies your integration.
  • mysynctax_secret authenticates the request.
  • Both values are included in the JSON body.
  • Missing or invalid credentials may result in HTTP 401.

VB.NET 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.

Build the MyInvois Invoice Payload in VB.NET

The developer documentation defines header fields such as invoice_no, issue_date, sale_id_integrate and payment_note_term, together with item fields such as item ID, quantity, unit price, discount, tax and description.

Example VB.NET payload object
Dim payload = New With {

    .mysynctax_key = "YOUR_API_KEY",

    .mysynctax_secret = "YOUR_API_SECRET",

    .invoice_no = "INV-10001",

    .sale_id_integrate = 10001,

    .payment_note_term = "CASH",

    .items = New Object() {

        New With {

            .item_id = 101,

            .sorting_id = 1,

            .invoiced_quantity = 2,

            .unit_price = 30.0,

            .price_discount = 0,

            .tax_amount = 3.6,

            .item_description = "USB Keyboard"

        }

    }

}
Use the exact fields required by the endpoint you are calling. ERP invoice, normal invoice, self-billed invoice, note and master-data endpoints do not necessarily use identical payload structures.

VB.NET HttpClient MyInvois API Example

Save this reusable module as MySyncTaxClient.vb in a VB.NET project with the Newtonsoft.Json package. Set MYSYNCTAX_KEY and MYSYNCTAX_SECRET in the server environment, replace the sample invoice data, and call Await MySyncTaxClient.SubmitInvoiceAsync() from an async method. The module reuses an HTTP client and handles unsuccessful HTTP responses.

VB.NET – send an invoice request
Imports System

Imports System.Threading.Tasks

Imports System.Net.Http

Imports System.Text

Imports Newtonsoft.Json





Public Module MySyncTaxClient

    Private ReadOnly Client As New HttpClient() With {

        .Timeout = TimeSpan.FromSeconds(30)

    }



    Public Async Function SubmitInvoiceAsync() As Task(Of String)

        Dim apiKey = Environment.GetEnvironmentVariable("MYSYNCTAX_KEY")

        Dim apiSecret = Environment.GetEnvironmentVariable("MYSYNCTAX_SECRET")

        If String.IsNullOrWhiteSpace(apiKey) OrElse String.IsNullOrWhiteSpace(apiSecret) Then

            Throw New InvalidOperationException("Set MYSYNCTAX_KEY and MYSYNCTAX_SECRET.")

        End If

        Dim payload = New With {

            .mysynctax_key = apiKey,

            .mysynctax_secret = apiSecret,

            .invoice_no = "INV-10001",

            .sale_id_integrate = 10001,

            .payment_note_term = "CASH",

            .items = New Object() {

                New With {

                    .item_id = 101,

                    .sorting_id = 1,

                    .invoiced_quantity = 2,

                    .unit_price = 30.0,

                    .price_discount = 0,

                    .tax_amount = 3.6,

                    .item_description = "USB Keyboard"

                }

            }

        }



            Dim json As String = JsonConvert.SerializeObject(payload)

            Using content As New StringContent(json, Encoding.UTF8, "application/json")



            Using response As HttpResponseMessage = Await Client.PostAsync(

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

                content

            )



            Dim result As String = Await response.Content.ReadAsStringAsync()



            If response.IsSuccessStatusCode Then

                Return result

            End If



            Throw New ApplicationException(

                $"MySyncTax API error {(CInt(response.StatusCode))}: {result}"

            )

            End Using

            End Using

    End Function

End Module
For a production application, avoid creating a new HttpClient for every request. Reuse an instance where appropriate, apply timeouts, log correlation identifiers, and never hard-code live API secrets directly in source files.

VB.NET Send e-Invoice to LHDN and Handle UUID Responses

A successful response can include a MySyncTax UUID and a QR URL. Your application should deserialize the response and store identifiers needed for future status checks, printing or support workflows.

Example Success Response

{

  "status": "ok",

  "mysynctax_uuid": "generated-unique-id",

  "qr_url": "https://mysynctax.com/v5/redirect/..."

}

Deserialize in VB.NET

Dim data = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(result)



If data.ContainsKey("status") Then

    Dim status As String = data("status").ToString()

End If



If data.ContainsKey("mysynctax_uuid") Then

    Dim uuid As String = data("mysynctax_uuid").ToString()

End If

Useful MySyncTax Endpoints for VB.NET Systems

Choose the endpoint based on the business workflow your VB.NET application needs to support.

Workflow Method Endpoint Typical VB.NET Use
Normal invoice POST /v5/api/myinvois POS or basic invoice submission
ERP invoice with customer POST /v5/api/myinvois/invoice ERP/accounting application with customer master data
Credit / debit / refund note POST /v5/api/myinvois/note Adjust an invoice previously submitted
Self-billed invoice POST /v5/api/myinvois/selfbill/invoice Buyer-generated invoice workflow
Add/update customer POST /v5/api/myinvois/add_customer Synchronize customer master data
Add/update supplier POST /v5/api/myinvois/add_supplier Synchronize supplier data for ERP/self-billed flows

Full API reference: https://mysynctax.com/v5/developer/documentation

VB.NET Error Handling for MyInvois API Integration

Do not treat every failed request as a retryable network error. The API documentation lists several HTTP responses that should be handled according to their meaning.

400

Invalid JSON

Log the response, validate required fields and check that numeric amounts are sent as numbers rather than strings.

401

Unauthorized

Verify mysynctax_key and mysynctax_secret. Avoid automatic retries with the same invalid credentials.

409

Duplicate Submission

Use your transaction ID and stored API response to avoid blindly submitting an identical invoice payload multiple times.

VB.NET status handling pattern
Select Case CInt(response.StatusCode)

    Case 200 To 299

        ' Success: parse and store response.



    Case 400

        ' Invalid or malformed JSON.



    Case 401

        ' Missing or invalid API credentials.



    Case 409

        ' Duplicate invoice submission.



    Case 500

        ' Server processing error. Log before retrying.



    Case Else

        ' Handle unexpected status codes.

End Select

Best Practices for MyInvois API Integration in VB.NET

A reliable integration is more than a successful POST request. Build the connection so finance and support teams can trace what happened to every transaction.

Protect Credentials

Keep keys and secrets in secure configuration or environment storage instead of placing them directly in source code or desktop UI fields.

Use Idempotent Business Logic

Store your own sale_id_integrate, request status and returned UUID so a network timeout does not automatically create an unnecessary resubmission.

Log Request Outcomes

Record timestamp, endpoint, local invoice number, HTTP status, MySyncTax UUID and a sanitized response for troubleshooting and audit support.

Validate Before Sending

Check required invoice and item fields, date formatting and numeric values before the HTTP request leaves your VB.NET application.

Handle Timeouts Gracefully

A timeout does not always prove the remote system rejected the transaction. Check your stored transaction state before retrying.

Separate API Logic

Put MySyncTax communication into a dedicated service class instead of mixing HTTP code directly into forms, reports or database event handlers.

Recommended VB.NET Project Structure

This separation keeps the MyInvois integration easier to test and maintain when endpoints or business rules change.

Suggested Classes

  • MySyncTaxClient.vb – HTTP communication.
  • InvoicePayload.vb – request model.
  • InvoiceResponse.vb – API response model.
  • InvoiceService.vb – application workflow and persistence.
  • ApiSettings.vb – endpoint and credential configuration.

Typical Flow

  • User confirms invoice in POS / ERP.
  • Application maps local invoice data to an API payload.
  • MySyncTaxClient serializes and submits JSON.
  • Application stores returned status and UUID.
  • UI displays success, duplicate or actionable error information.

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"

}

VB.NET HttpClient example

Keep the credentials in server-side environment configuration. Pass a reused HttpClient instance to this asynchronous method.

Imports System

Imports System.Collections.Generic

Imports System.Net.Http

Imports System.Text

Imports System.Text.Json

Imports System.Threading.Tasks



Private Async Function DeleteInvoiceAsync(httpClient As HttpClient) As Task(Of String)

    Dim mysynctax_uniqueId As String = "YOUR_INVOICE_UNIQUE_ID"

    Dim url As String = "https://mysynctax.com/v5/api/myinvois/delete/" &

        Uri.EscapeDataString(mysynctax_uniqueId)



    Dim apiKey = Environment.GetEnvironmentVariable("MYSYNCTAX_KEY")

    Dim apiSecret = Environment.GetEnvironmentVariable("MYSYNCTAX_SECRET")

    If String.IsNullOrWhiteSpace(apiKey) OrElse String.IsNullOrWhiteSpace(apiSecret) Then

        Throw New InvalidOperationException("MySyncTax credentials are not configured.")

    End If



    Dim payload As New Dictionary(Of String, String) From {

        {"mysynctax_key", apiKey},

        {"mysynctax_secret", apiSecret}

    }

    Dim json As String = JsonSerializer.Serialize(payload)



    Using content As New StringContent(json, Encoding.UTF8, "application/json")

        Using response As HttpResponseMessage = Await httpClient.PostAsync(url, content)

            Dim responseBody As String = Await response.Content.ReadAsStringAsync()

            response.EnsureSuccessStatusCode()

            Return responseBody

        End Using

    End Using

End Function

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.

FAQ – MyInvois API Integration VB.NET

Common implementation questions for Visual Basic .NET developers integrating Malaysian e-Invoice workflows.

Can VB.NET call the MySyncTax MyInvois API?

Yes. VB.NET can use HttpClient to send HTTPS POST requests with JSON content and read the JSON response returned by MySyncTax.

What authentication fields are required?

The developer documentation states that integration requests include mysynctax_key and mysynctax_secret in the JSON body.

Which JSON library should I use in VB.NET?

The documentation example uses JsonConvert.SerializeObject, which is provided by Newtonsoft.Json. You can keep that approach for compatibility with the sample implementation.

How do I prevent duplicate e-Invoice submissions?

Persist your local transaction ID and API result, then check the transaction state before retrying. The documentation notes that duplicate JSON payloads may be rejected with HTTP 409.

Can an ERP system submit customer data with the invoice?

Yes. The documentation provides an ERP invoice endpoint that accepts customer master data together with invoice items.

Does MySyncTax support self-billed invoices and notes?

The API documentation includes endpoints for self-billed invoices as well as credit, debit and refund note workflows.

Can a VB.NET WinForms or ERP system use a MyInvois sandbox?

The current MySyncTax developer documentation does not list a VB.NET-specific sandbox endpoint. A VB.NET application can use the documented REST API pattern, while test-versus-production access and credentials should be confirmed with MySyncTax before live submission.

Need Help with MyInvois API Integration in VB.NET?

If you are connecting a legacy VB.NET desktop system, ERP, accounting application or POS to Malaysian e-Invoice workflows, use the developer documentation as your implementation reference and contact the MySyncTax integration team for onboarding details.