# Malaysia v2: Cancel Document API

Cancel a document by its document ID, with a reason, in the Malaysia LHDN API v2 (legacy): endpoint, headers, request, responses and code examples.

> **Legacy API v2**
>
> This page documents API v2 for Malaysia, which is no longer developed. Start new integrations on the current API: see the [Unify API reference](https://docs.complyance.io/api-reference/unify/) and the [Malaysia guide](https://docs.complyance.io/countries/my/).

**This endpoint may no longer be available.** Contact <support@complyance.io> before you rely on it. To cancel a Malaysian document within LHDN’s 72-hour window, you can cancel it in the MyInvois portal; see [the life of a Malaysian e-invoice](https://docs.complyance.io/countries/my/#the-life-of-a-malaysian-e-invoice).

The Cancel Document API cancels a document by its `documentId`. You must give a reason for the cancellation.

## Endpoint

| Environment | Host |
| - | - |
| Sandbox | `https://malaysia-sandbox.complyance.io` |
| Production | `https://malaysia-prod.complyance.io` |

```http title="Cancel a document"
POST https://malaysia-sandbox.complyance.io/cancelDocument
POST https://malaysia-prod.complyance.io/cancelDocument
```

## Headers

| Header | Type | Description | Example | Conditionality |
| - | - | - | - | - |
| `x-api-key` | string | Your API key | `your-api-key` | Mandatory |
| `Content-Type` | string | Set as `application/json` | `application/json` | Mandatory |

## Request body

The request body is JSON.

| Parameter | Type | Description | Example value |
| - | - | - | - |
| `documentId` | string | Document reference number the supplier uses for internal tracking. | `E-INV-01` |
| `reason` | string | The reason for cancelling the document. | `Testing Cancellation` |

```json title="Request body"
{
  "documentId": "E-INV-01",
  "reason": "Testing Cancellation"
}
```

## Response

### Success response

HTTP status `200 OK`:

```json title="Response"
{
  "uuid": "ABCDEFGHJK0123456789CANC10",
  "status": "Cancelled",
  "error": null
}
```

### Error responses

| HTTP status code | Error code | Description |
| - | - | - |
| `400` | `BAD_REQUEST` | The input is invalid or fields are missing. |
| `401` | `UNAUTHORIZED` | The API key is missing or invalid. |
| `500` | `SERVER_ERROR` | An internal server error occurred. |

```json title="Error response"
{
  "errorMessage": "Please check the field documentId"
}
```

## Code examples

**Shell**

```bash
curl --location 'https://malaysia-prod.complyance.io/cancelDocument' \
--header 'Content-Type: application/json' \
--header 'x-api-key: your-api-key' \
--data '{
  "documentId": "E-INV-01",
  "reason": "Testing Cancellation"
}'
```

**JavaScript**

```javascript
const headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'your-api-key'
};

const body = {
  documentId: "E-INV-01",
  reason: 'Testing Cancellation'
};

fetch('https://malaysia-prod.complyance.io/cancelDocument', {
  method: 'POST',
  headers: headers,
  body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```

**Python**

```python
import requests

url = 'https://malaysia-prod.complyance.io/cancelDocument'
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'your-api-key'
}
data = {
  'documentId': 'E-INV-01',
  'reason': 'Testing Cancellation'
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
```

**PHP**

```php
<?php

$url = 'https://malaysia-prod.complyance.io/cancelDocument';
$headers = [
  'Content-Type: application/json',
  'x-api-key: your-api-key'
];
$data = [
  'documentId' => 'E-INV-01',
  'reason' => 'Testing Cancellation'
];

$options = [
  'http' => [
    'header'  => $headers,
    'method'  => 'POST',
    'content' => json_encode($data)
  ]
];

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>
```

**Java**

```java
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws Exception {
    URL url = new URL("https://malaysia-prod.complyance.io/cancelDocument");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("POST");
    con.setRequestProperty("Content-Type", "application/json");
    con.setRequestProperty("x-api-key", "your-api-key");
    con.setDoOutput(true);

    String jsonInputString = "{\"documentId\": \"E-INV-01\", \"reason\": \"Testing Cancellation\"}";

    try (OutputStream os = con.getOutputStream()) {
      byte[] input = jsonInputString.getBytes("utf-8");
      os.write(input, 0, input.length);
    }

    try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))) {
      StringBuilder response = new StringBuilder();
      String responseLine = null;
      while ((responseLine = br.readLine()) != null) {
        response.append(responseLine.trim());
      }
      System.out.println(response.toString());
    }
  }
}
```

**Go**

```go
package main

import (
  "bytes"
  "net/http"
  "io/ioutil"
  "fmt"
)

func main() {
  url := "https://malaysia-prod.complyance.io/cancelDocument"
  jsonData := []byte(`{"documentId": "E-INV-01", "reason": "Testing Cancellation"}`)

  req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
  if err != nil {
    fmt.Println("Error creating request:", err)
    return
  }

  req.Header.Set("Content-Type", "application/json")
  req.Header.Set("x-api-key", "your-api-key")

  client := &http.Client{}
  resp, err := client.Do(req)
  if err != nil {
    fmt.Println("Error making request:", err)
    return
  }
  defer resp.Body.Close()

  body, _ := ioutil.ReadAll(resp.Body)
  fmt.Println(string(body))
}
```

## Notes

- The `x-api-key` header must contain a valid API key.
- The `reason` parameter is required. Give a clear explanation for the cancellation.
- Use the sandbox host for testing.
- Format the request body and headers correctly to avoid errors.

Last updated 9 October 2026

Source: https://docs.complyance.io/legacy/v2/malaysia/api-cancel-document/
