# Delete Invoice

This API allows you to delete an invoice from ClearTax database before it's submitted to LHDN for generation. It takes the document id for the document to be deleted as the input and returns the status of the activity, along with error messages, if any.

### Request Method

DELETE

### Request URL

```
{{HOST}}/einvoice/v1/documents/{document_id}/
```

### Request Headers

| Parameter             | Data Type | Field Validations                              | Description                                                                                     |
| --------------------- | --------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| x-cleartax-auth-token | String    | Cannot be empty                                | Mandatory. User auth token.                                                                     |
| x-clear-tin           | String    | Cannot be empty                                | Mandatory. TIN of the entity                                                                    |
| x-clear-branch        | String    | Should be a valid branch from the user account | Optional. Branch name (store name) added in the user account which maps to a TIN of the entity. |
| x-request-id          | UUID      | Should be unique for every request             | Optional. Unique request ID.                                                                    |
| Content-Type          | String    | application/json                               | application/json                                                                                |

### Request Path Params

| Parameter    | Data Type | Field Validations             | Description                                                       |
| ------------ | --------- | ----------------------------- | ----------------------------------------------------------------- |
| document\_id | String    | Should be a valid document id | Mandatory. Unique document id present in the upload api response. |

### Request Query Params

| Parameter     | Data Type | Field Validations           | Description    |
| ------------- | --------- | --------------------------- | -------------- |
| einvoice-type | ENUM      | SALES, PURCHASE, SALES\_B2C | Default: SALES |

### Request Body

There will be no request body for this API.

### Sample Request

Request Body

```
NA
```

### Response Status Codes

| HTTP Status Code | Description                                        |
| ---------------- | -------------------------------------------------- |
| 200              | For a successful status check                      |
| 400              | For any kind of invalid payload issues             |
| 401              | If the user is not authenticated for the operation |
| 403              | If the user is not authorized for the operation    |
| 429              | Too many requests                                  |

### Response Schema

| Parameter | Data Type | Field Validations | Description             |
| --------- | --------- | ----------------- | ----------------------- |
| success   | String    | NA                | <p><br>Status</p>       |
| message   | String    | NA                | Delete Response Message |

#### Error Details Object

| Parameter    | Data Type | Field Validations | Description                                                                                                      |
| ------------ | --------- | ----------------- | ---------------------------------------------------------------------------------------------------------------- |
| ErrorCode    | String    | Cannot be null    | A code to identify the error. Error codes are published below.                                                   |
| ErrorMessage | String    | Cannot be null    | Human readable error message.                                                                                    |
| ErrorSource  | String    | LHDN, CLEARTAX    | Source of the error.                                                                                             |
| ErrorPath    | String    | NA                | <p>If it is a validation error of a request data, it will point to the request data field.<br>Example below.</p> |

### Sample Response (Success)

HTTP Status Code: 200

Response Body

```json
{
    "success": "true",
    "message": "Document deleted successfully with document Id : 67d1c47a4d78d477fdf49ab5"
}
```

### Sample Response (Error)

Case1: Document not present with document id passed

HTTP Status Code

200

Response Body

```json
{
    "ErrorDetails": [
        {
            "ErrorCode": "300102",
            "ErrorMessage": "You don't have any data present for the selected Document Details",
            "ErrorSource": "CLEARTAX",
            "Path": null
        }
    ]
}
```

Case 2: When document is already submitted to the LHDN

HTTP Status Code

200

Response Body

```json
{
    "ErrorDetails": [
        {
            "ErrorCode": "300108",
            "ErrorMessage": "You can only delete Invoices in Not Generated state.",
            "ErrorSource": "CLEARTAX",
            "Path": null
        }
    ]
}
```

### API Validations

1. A valid document with {document\_id} in path params should be present.

### API Constraints

1. This API needs to be authenticated with a valid user authentication token. If the auth token is not present or is invalid, the API will return HTTP Status Code 401.
2. Each customer is allowed to send a limited number of requests per minute to prevent server overload. If the limit is exceeded, the server will respond with a 429 Too Many Requests status code.
3. If the auth token is valid, but the user does not have the authorization to generate e-invoice for a document, then the API will return HTTP Status Code 403. The user, whose auth token is used, should have an Admin role for the particular TIN used in the request.
4. Rate Limit: The below rate limits are in line with those applied by LHDN.&#x20;

   **Production - 500 API calls per minute with a burst capacity of 25 API calls**

   **Sandbox - 500 API calls per minute with a burst capacity of 25 API calls**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cleartax.in/cleartax-docs/e-invoicing-malaysia-api/e-invoicing-malaysia-api-reference/api-lists/delete-invoice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
