# Write off 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)

Write off the specified invoice.

Use this operation to mark invoices as settled when they remain unpaid after multiple attempts to collect payment.

#### Reverse a write-off[](#reverse-a-write-off)

You can reverse the write-off by [removing the linked credit note](/docs/api/invoices/remove-credit-note-from-an-invoice).

### Prerequisites & Constraints

-   There must be no in-progress payments for the invoice.
-   The invoice `status` must be `payment_due`, `posted`, or `not_paid`.

### Impacts

**

Invoice

**

-   Chargebee sets the invoice `status` to `paid`.
-   Chargebee sets the invoice `write_off_amount` to the invoice `amount_due`.

**

Credit Note

**

-   Chargebee creates a credit note with the following attributes:
    -   `type` is `adjustment`.
    -   `create_reason_code` is `Write Off`.
    -   `total` is `invoice.amount_due`.

**

Payment Schedules

**

-   If the invoice has an associated [`payment_schedule`](/docs/api/payment_schedules) [created](/docs/api/invoices/apply-payment-schedule-scheme-to-an-invoice) against it, Chargebee marks the schedule as paid. Chargebee sets [`schedule_entries[].status`](/docs/api/payment_schedules/payment_schedule-object#schedule_entries) to `paid`.

**

RevRec

**

-   To understand how write-offs sync to RevRec, see the [write-off sync documentation](https://www.chargebee.com/docs/revrec/revenue-recognition/recognizing-chargebee-credit-notes#use-case-cancel-write-off).
-   To understand how write-offs affect bad debt expenses in RevRec, see the [bad debt expense documentation](https://www.chargebee.com/docs/revrec/revenue-recognition/bad-debt-expense).

**

Accounting Integrations

**

-   Write-offs sync to accounting platforms based on configured sync rules. For more details, see the following documentation:
    -   [Intacct](https://www.chargebee.com/docs/billing/2.0/integrations/intacct-config#account-mapping-for-invoice-line-items)
    -   [NetSuite](https://www.chargebee.com/docs/billing/2.0/integrations/netsuite-config)

### Implementation Notes

Before calling this API, ensure the following:

-   `invoice.status` is `payment_due`, `posted`, or `not_paid`.
-   `invoice.linked_payments[i].txn_status` is not `in_progress`. If it is, then wait for the `txn_status` to be finalized.

## Sample Request

#### cURL

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

#### .NET

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

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

Invoice invoice = result.Invoice;
CreditNote creditNote = result.CreditNote;
```

#### 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.WriteOff("__demo_inv__4", nil).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        CreditNote := res.CreditNote
    }
}
```

#### 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.InvoiceWriteOffRequest{}
  res, err := client.Invoice.WriteOff("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        CreditNote := res.CreditNote
    }
}
```

#### 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.writeOff("__demo_inv__4").request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceWriteOffParams;
import com.chargebee.v4.models.invoice.responses.InvoiceWriteOffResponse;

public class InvoiceWriteOff {

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

        InvoiceWriteOffResponse response = client.invoices().writeOff("__demo_inv__4");

        Invoice invoice = response.getInvoice();
        CreditNote creditNote = response.getCreditNote();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

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

    console.log(result);
    const invoice = result.invoice;
    const creditNote = result.credit_note;
} 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()->writeOff("__demo_inv__4");
$invoice = $result->invoice;
$creditNote = $result->credit_note;
```

#### Python

```python
from chargebee import Chargebee

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

#### Ruby

```ruby
require 'chargebee'

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

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

invoice = result.invoice
credit_note = result.credit_note
```

## Sample Response

```json
{
  "credit_note": {
    "allocations": [
      {
        "allocated_amount": 1000,
        "allocated_at": 1517490684,
        "invoice_date": 1612797080,
        "invoice_id": "__demo_inv__4",
        "invoice_status": "paid"
      },
      {..}
    ],
    "amount_allocated": 1000,
    "amount_available": 0,
    "amount_refunded": 0,
    "base_currency_code": "USD",
    "create_reason_code": "Write Off",
    "currency_code": "USD",
    "customer_id": "__test__8asySSOcV0r62s",
    "date": 1517490684,
    "deleted": false,
    "exchange_rate": 1,
    "fractional_correction": 0,
    "id": "__demo_cn__1",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8asySSOcV0r62s",
        "date_from": 1517490684,
        "date_to": 1517490684,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8asyKSOcV2xV8q",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asySSOcV0r62s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_refunds": {},
    "object": "credit_note",
    "price_type": "tax_exclusive",
    "reason_code": "write_off",
    "reference_invoice_id": "__demo_inv__4",
    "refunded_at": 1517490684,
    "resource_version": 1517490684670,
    "round_off_amount": 0,
    "status": "adjusted",
    "sub_total": 1000,
    "subscription_id": "__test__8asySSOcV0r62s",
    "taxes": {},
    "total": 1000,
    "type": "adjustment",
    "updated_at": 1517490684
  },
  "invoice": {
    "adjustment_credit_notes": [
      {
        "cn_create_reason_code": "Write Off",
        "cn_date": 1517490684,
        "cn_id": "__demo_cn__1",
        "cn_reason_code": "write_off",
        "cn_status": "adjusted",
        "cn_total": 1000
      },
      {..}
    ],
    "amount_adjusted": 1000,
    "amount_due": 0,
    "amount_paid": 0,
    "amount_to_collect": 0,
    "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__8asySSOcV0r62s",
    "date": 1612797080,
    "deleted": false,
    "due_date": 1612797080,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1612797081,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8asySSOcV2l83v",
        "txn_amount": 1000,
        "txn_status": "failure"
      },
      {..}
    ],
    "dunning_status": "stopped",
    "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__8asySSOcV0r62s",
        "date_from": 1612797080,
        "date_to": 1612883480,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8asySSOcV2hz3u",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asySSOcV0r62s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1612797081,
        "txn_amount": 1000,
        "txn_date": 1612797081,
        "txn_id": "txn___test__8asySSOcV2l83v",
        "txn_status": "failure"
      },
      {..}
    ],
    "net_term_days": 0,
    "object": "invoice",
    "paid_at": 1517490684,
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517490684658,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 1000,
    "subscription_id": "__test__8asySSOcV0r62s",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517490684,
    "write_off_amount": 1000
  }
}
```

## URL Format

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

## Input Parameters

- `comment` (optional, string, max chars=300)
  An internal [comment](/docs/api/comments) to be added for this operation, to the invoice. This comment is displayed on the Chargebee UI. It is not displayed on any customer-facing [Hosted Page](/docs/api/hosted_pages) or any document such as the [Invoice PDF](/docs/api/invoices/retrieve-invoice-as-pdf) .

## Returns

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

- `credit_note` (Credit note object)
  Resource object representing credit\_note
