# Delete an invoice

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

[Asynchronous](/docs/api/async_response/async-response-object)

Deletes the specified invoice.

#### Void the invoice[](#void-the-invoice)

If the invoice was generated incorrectly, [void](/docs/api/invoices/void-an-invoice) it instead of deleting it. Voiding preserves the audit trail and allows for future reference and compliance without removing the original record.

#### Regenerate or import an invoice[](#regenerate-or-import-an-invoice)

-   If the invoice is for the current term of a subscription, you may regenerate it using the [Regenerate an invoice API](/docs/api/subscriptions/regenerate-an-invoice).
-   If the invoice is not for the current term of a subscription, you may import it using the [Import an invoice API](/docs/api/invoices/import-invoice) or the UI [bulk import](https://www.chargebee.com/docs/2.0/bulk-operations.html#overview_available-bulk-operations) action.

### Prerequisites & Constraints

-   The invoice should not have any [`linked_payments`](/docs/api/invoices/invoice-object#linked_payments) with `txn_status` as `success` or `in_progress`.
-   The `amount_adjusted` on the invoice should be zero.
-   The invoice should not have any [`applied_credits`](/docs/api/invoices/invoice-object#applied_credits) with `cn_status` as `refunded` or `refund_due`.
-   The invoice should not have any [`issued_credit_notes`](/docs/api/invoices/invoice-object#issued_credit_notes) with `cn_status` as `refunded` or `refund_due`.
-   The invoice should not have any [`linked_taxes_withheld`](/docs/api/invoices/invoice-object#linked_taxes_withheld).
-   The invoice must not belong to a [gift subscription](/docs/api/gifts).

### Impacts

**

Invoices

**

-   The invoice is marked as `deleted` = `true` and can only be retrieved using the [List invoices API](/docs/api/invoices/list-invoices) by using the parameter `include_deleted=true`.
-   If the invoice is the first invoice for a subscription or customer (`invoice.first_invoice` = `true`), the next invoice generated for the subscription or customer is marked as the first invoice.

**

Subscription

**

-   If the invoice is for the current term of a subscription and the subscription is changed later with [proration](/docs/api/subscriptions/update-subscription-for-items#prorate) enabled, no prorated credits are issued.

**

Usages

**

-   Deleting an invoice permanently deletes all associated [usages](/docs/api/usages). To regenerate the data, [add](/docs/api/usages/create-a-usage) or [bulk import](https://www.chargebee.com/docs/2.0/bulk-operations.html#overview_available-bulk-operations) usages and then regenerate the invoice.

**

Usage Events

**

-   Deleting an invoice does **not** delete the associated [`usage_event`](/docs/api/usage_events) resources.

**

Integrations

**

-   Verify the impacts of deleting an invoice on your [accounting](https://www.chargebee.com/docs/billing/2.0/integrations/finance-integration-index) integrations.

### Implementation Notes

Before calling this API, ensure the following:

-   [Remove](/docs/api/invoices/remove-payment-from-an-invoice) any `linked_payments` with `txn_status` as `success` or `in_progress`.
-   [Remove](/docs/api/invoices/remove-credit-note-from-an-invoice) the following credits:
    -   any `applied_credits` with `cn_status` as `refunded` or `refund_due`
    -   any `issued_credit_notes` with `cn_status` as `refunded` or `refund_due`
    -   any `adjustment_credit_notes` with `cn_status` as `adjusted`
-   [Remove](/docs/api/invoices/remove-tax-withheld-for-an-invoice) any `linked_taxes_withheld`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/delete \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.Delete("__demo_inv__4").Request();

Invoice invoice = result.Invoice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    invoiceAction "github.com/chargebee/chargebee-go/v3/actions/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.Delete("__demo_inv__4", nil).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.InvoiceDeleteRequest{}
  res, err := client.Invoice.Delete("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Invoice.delete("__demo_inv__4").request();

        Invoice invoice = result.invoice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceDeleteParams;
import com.chargebee.v4.models.invoice.responses.InvoiceDeleteResponse;

public class InvoiceDelete {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        InvoiceDeleteResponse response = client.invoices().delete("__demo_inv__4");

        Invoice invoice = response.getInvoice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.invoice.delete("__demo_inv__4");

    console.log(result);
    const invoice = result.invoice;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->invoice()->delete("__demo_inv__4");
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.delete("__demo_inv__4")
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Invoice.delete("__demo_inv__4")

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 1000,
    "amount_paid": 0,
    "amount_to_collect": 1000,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Rachel",
      "last_name": "Green",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8asnHSOcU9yY2s",
    "date": 1612796877,
    "deleted": false,
    "due_date": 1612796877,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1612796878,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8asnHSOcUCAN3v",
        "txn_amount": 1000,
        "txn_status": "failure"
      },
      {..}
    ],
    "dunning_status": "in_progress",
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": false,
    "id": "__demo_inv__4",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8asnHSOcU9yY2s",
        "date_from": 1612796877,
        "date_to": 1612883277,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8asnHSOcUC6o3u",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asnHSOcU9yY2s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1612796878,
        "txn_amount": 1000,
        "txn_date": 1612796878,
        "txn_id": "txn___test__8asnHSOcUCAN3v",
        "txn_status": "failure"
      },
      {..}
    ],
    "net_term_days": 0,
    "next_retry_at": 1612883278,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1612796878750,
    "round_off_amount": 0,
    "status": "payment_due",
    "sub_total": 1000,
    "subscription_id": "__test__8asnHSOcU9yY2s",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1612796878,
    "write_off_amount": 0
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/invoices/{invoice-id}/delete

## Input Parameters

- `comment` (optional, string, max chars=300)
  Reason for deleting the invoice. This comment will be added to the subscription entity if the invoice belongs to a subscription. It is added to the customer entity if the invoice is associated only with a customer.

- `claim_credits` (optional, boolean, default=false)
  Indicates whether to put prorated credits back to the subscription or ignore while deleting the invoice.

## Returns

- `invoice` (Invoice object)
  Resource object representing invoice
