# Malaysia v2: Delete Receipt API

Delete an existing receipt by its receipt number in the Malaysia LHDN API v2 (legacy): endpoint, headers, parameters, 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/).

The Delete Receipt API deletes an existing receipt. Use it to remove outdated or incorrect receipts created with the [Create Receipt API](https://docs.complyance.io/legacy/v2/malaysia/api-create-receipt/).

## Endpoint

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

```http title="Delete a receipt"
POST https://malaysia-sandbox.complyance.io/deleteReceipt?receiptNumber=
POST https://malaysia-prod.complyance.io/deleteReceipt?receiptNumber=
```

## 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 parameters

| Parameter | Description | Required | Example |
| - | - | - | - |
| `receiptNumber` | Receipt identifier | Yes | `Receipt/002/PQRS` |

The code examples below send `receiptNumber` in the JSON request body, with an empty `receiptNumber=` query parameter in the URL.

## Response

### Success response

HTTP status `200 OK`:

```json title="Response"
{
  "status": "success",
  "message": "Receipt deleted successfully."
}
```

### 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. |
| `404` | `NOT_FOUND` | The receipt does not exist. |
| `500` | `SERVER_ERROR` | An internal server error occurred. |

```json title="Error response"
{
  "status": "error",
  "message": "Receipt not found or already deleted."
}
```

## Code examples

**Shell**

```bash
curl --location 'https://malaysia-prod.complyance.io/deleteReceipt?receiptNumber=' \
--header 'Content-Type: application/json' \
--header 'x-api-key: your-api-key' \
--data '{
  "receiptNumber": "RCPT-2025-0001"
}'
```

**JavaScript**

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

const body = {
  receiptNumber: 'RCPT-2025-0001'
};

fetch('https://malaysia-prod.complyance.io/deleteReceipt?receiptNumber=', {
  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/deleteReceipt?receiptNumber='
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'your-api-key'
}
data = {
  'receiptNumber': 'RCPT-2025-0001'
}

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

**PHP**

```php
<?php

$url = 'https://malaysia-prod.complyance.io/deleteReceipt?receiptNumber=';
$headers = [
  'Content-Type: application/json',
  'x-api-key: your-api-key'
];
$data = [
  'receiptNumber' => 'RCPT-2025-0001'
];

$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/deleteReceipt?receiptNumber=");
    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 = "{\"receiptNumber\": \"RCPT-2025-0001\"}";

    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/deleteReceipt?receiptNumber="
  jsonData := []byte(`{"receiptNumber": "RCPT-2025-0001"}`)

  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 `receiptNumber` parameter is required and must match an existing receipt.
- Use the sandbox host for testing.
- Format the request body and headers correctly to avoid errors.

Source: https://docs.complyance.io/legacy/v2/malaysia/api-delete-receipt/
