# Create credit note

> 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)

Creates a credit note for the specified invoice.

### Impacts

**

Invoice

**

See [Impact on reference invoice](/docs/api/credit_notes/credit-note-object#ref-invoice-impact).

**

Credit note

**

-   A new credit note of the specified `type` is created.
-   If the credit note `type` is `adjustment`:
    -   `total` and `amount_allocated` are set to the adjusted amount.
    -   `status` is set to `adjusted`.
-   If the credit note `type` is `refundable` or `store`:
    -   `total` and `amount_available` are set to the refundable amount.
    -   `status` is set to `refund_due`.
-   The `taxes[].amount` and `line_item_taxes[].tax_amount` are set to the corresponding values on the invoice, prorated by the ratio of `credit_note.total` to `invoice.total`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_notes \
     -u {site_api_key}:\
     -d reference_invoice_id="__demo_inv__1" \
     -d total=500 \
     -d type="REFUNDABLE" \
     -d reason_code="PRODUCT_UNSATISFACTORY" \
     -d customer_notes="Products were returned because they were defective"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditNote.Create()
		.ReferenceInvoiceId("__demo_inv__1")
		.Total(500)
		.Type(CreditNote.TypeEnum.Refundable)
		.ReasonCode(CreditNote.ReasonCodeEnum.ProductUnsatisfactory)
		.CustomerNotes("Products were returned because they were defective")
		.Request();

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

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    creditnoteAction "github.com/chargebee/chargebee-go/v3/actions/creditnote"
    "github.com/chargebee/chargebee-go/v3/models/creditnote"
    creditNoteEnum "github.com/chargebee/chargebee-go/v3/models/creditnote/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditnoteAction.Create(&creditnote.CreateRequestParams{
        ReferenceInvoiceId : "__demo_inv__1",
        Total : chargebee.Int64(500),
        Type : creditNoteEnum.TypeRefundable,
        ReasonCode : creditNoteEnum.ReasonCodeProductUnsatisfactory,
        CustomerNotes : "Products were returned because they were defective",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        CreditNote := res.CreditNote
        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.CreditNoteCreateRequest{
    ReferenceInvoiceId : "__demo_inv__1",
    Total : chargebee.Int64(500),
    Type : chargebee.CreditNoteTypeRefundable,
    ReasonCode : chargebee.CreditNoteReasonCodeProductUnsatisfactory,
    CustomerNotes : "Products were returned because they were defective",
}
  res, err := client.CreditNote.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        CreditNote := res.CreditNote
        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 = CreditNote.create()
            .referenceInvoiceId("__demo_inv__1")
            .total(500L)
            .type(CreditNote.Type.REFUNDABLE)
            .reasonCode(CreditNote.ReasonCode.PRODUCT_UNSATISFACTORY)
            .customerNotes("Products were returned because they were defective")
            .request();

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

#### Java

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

public class CreditNoteCreate {

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

        CreditNoteCreateParams params = CreditNoteCreateParams.builder()
            .referenceInvoiceId("__demo_inv__1")
            .total(500L)
            .type(CreditNoteCreateParams.Type.REFUNDABLE)
            .reasonCode(CreditNoteCreateParams.ReasonCode.PRODUCT_UNSATISFACTORY)
            .customerNotes("Products were returned because they were defective")
            .build();

        CreditNoteCreateResponse response = client.creditNotes().create(params);

        CreditNote creditNote = response.getCreditNote();
        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.creditNote.create({
        reference_invoice_id: "__demo_inv__1",
        total: 500,
        type: "refundable",
        reason_code: "product_unsatisfactory",
        customer_notes: "Products were returned because they were defective"
    });

    console.log(result);
    const creditNote = result.credit_note;
    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->creditNote()->create([
    "reference_invoice_id" => "__demo_inv__1",
    "total" => 500,
    "type" => "refundable",
    "reason_code" => "product_unsatisfactory",
    "customer_notes" => "Products were returned because they were defective"
]);
$creditNote = $result->credit_note;
$invoice = $result->invoice;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditNote.create(
    cb_client.CreditNote.CreateParams(
        reference_invoice_id="__demo_inv__1",
        total=500,
        type=chargebee.CreditNote.Type.REFUNDABLE,
        reason_code=chargebee.CreditNote.ReasonCode.PRODUCT_UNSATISFACTORY,
        customer_notes="Products were returned because they were defective"
    )
)
credit_note = response.credit_note
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::CreditNote.create({
  :reference_invoice_id => "__demo_inv__1",
  :total => 500,
  :type => "REFUNDABLE",
  :reason_code => "PRODUCT_UNSATISFACTORY",
  :customer_notes => "Products were returned because they were defective"
})

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

## Sample Response

```json
{
  "credit_note": {
    "allocations": {},
    "amount_allocated": 0,
    "amount_available": 500,
    "amount_refunded": 0,
    "base_currency_code": "USD",
    "create_reason_code": "Product Unsatisfactory",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWSy4m5e",
    "date": 1517501405,
    "deleted": false,
    "exchange_rate": 1,
    "exchange_rates": [
      {
        "currency_code": "EUR",
        "rate": 1.154
      },
      {..}
    ],
    "fractional_correction": 0,
    "id": "__demo_cn__1",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 500,
        "customer_id": "__test__KyVnHhSBWSy4m5e",
        "date_from": 1517501405,
        "date_to": 1517501405,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__KyVnHhSBWSyHE5r",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 500
      },
      {..}
    ],
    "linked_refunds": {},
    "object": "credit_note",
    "price_type": "tax_exclusive",
    "reason_code": "product_unsatisfactory",
    "reference_invoice_id": "__demo_inv__1",
    "resource_version": 1517501405000,
    "round_off_amount": 0,
    "status": "refund_due",
    "sub_total": 500,
    "taxes": {},
    "total": 500,
    "type": "refundable",
    "updated_at": 1517501405
  },
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 0,
    "amount_paid": 1000,
    "amount_to_collect": 0,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Duncan",
      "last_name": "Walpole",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWSy4m5e",
    "date": 1517501404,
    "deleted": false,
    "due_date": 1517501404,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "exchange_rates": [
      {
        "currency_code": "EUR",
        "rate": 1.154
      },
      {..}
    ],
    "first_invoice": true,
    "has_advance_charges": false,
    "id": "__demo_inv__1",
    "is_gifted": false,
    "issued_credit_notes": [
      {
        "cn_create_reason_code": "Product Unsatisfactory",
        "cn_date": 1517501405,
        "cn_id": "__demo_cn__1",
        "cn_reason_code": "product_unsatisfactory",
        "cn_status": "refund_due",
        "cn_total": 500
      },
      {..}
    ],
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__KyVnHhSBWSy4m5e",
        "date_from": 1517501404,
        "date_to": 1517501404,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__KyVnHhSBWSy9k5l",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1517501404,
        "txn_amount": 1000,
        "txn_date": 1517501404,
        "txn_id": "txn___test__KyVnHhSBWSyEh5m",
        "txn_status": "success"
      },
      {..}
    ],
    "net_term_days": 0,
    "new_sales_amount": 1000,
    "object": "invoice",
    "paid_at": 1517501404,
    "price_type": "tax_exclusive",
    "recurring": false,
    "resource_version": 1517501405000,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 1000,
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517501405,
    "write_off_amount": 0
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/credit_notes

## Input Parameters

- `reference_invoice_id` (optional, string, max chars=50)
  The identifier of the invoice against which this credit note is issued.
  
  **Required when**
  
  -   `type` is `adjustment` or `store`.
  
  **Note** When not provided and `type` is `refundable`, then `customer_id` must be provided because this creates a [standalone credit note](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/credit-notes#standalone-credits).

- `customer_id` (optional, string, max chars=50)
  The identifier of the customer for whom this credit note is issued.
  
  **Required when**
  
  -   `type` is `refundable` and `reference_invoice_id` is not provided. This creates a [standalone credit note](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/credit-notes#standalone-credits).

- `total` (optional, in cents, default=0, min=0)
  The total credit note amount.
  
  **Constraints**
  
  -   Pass either the `total` or `line_items` parameter.
  -   If `type` is `adjustment`, `total` must not exceed the amount due on the invoice minus the total amount of any transactions in progress for the invoice. Calculate this as `invoice.amount_due` minus the sum of `invoice.linked_payments[i].amount` where `invoice.linked_payments[i].txn_status` is `in_progress`.
  -   If `type` is `refundable` or `store`:
      -   If `reference_invoice_id` is provided, `total` must not exceed the refundable amount on the invoice. Calculate the refundable amount as the sum of:
          -   Sum of `linked_payments[i].amount` where `linked_payments[i].txn_status` is `success`
          -   Sum of `applied_credits[i].applied_amount` where `applied_credits[i].status` is not `voided`
          -   Sum of `linked_taxes_withheld[].amount`
          -   Minus the sum of `issued_credit_notes[i].cn_total` where `issued_credit_notes[i].status` is not `voided`
      -   If `reference_invoice_id` is not provided, there is no limit on the `total` because this creates a [standalone credit note](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/credit-notes#standalone-credits).

- `type` (required, enumerated string)
  The [type](/docs/api/credit_notes/credit-note-object) of credit note to create.
  
  **Prerequisites**
  
  -   If `type` is `adjustment`, the `invoice.status` must be `payment_due`, `posted` or `not_paid`.
  -   If `type` is `refundable` or `store`, the `invoice.status` must be `paid`, `payment_due`, `posted`, or `not_paid`.
  Possible enum values:
    - `adjustment`
      Creates an adjustment credit note.
      
      **Prerequisites**
      
      -   The `invoice.status` must be `payment_due`, `posted` or `not_paid`.
    - `refundable`
      Creates a refundable credit note.
      
      **Prerequisites**
      
      -   The `invoice.status` must be `paid`, `payment_due`, `posted`, or `not_paid`.
    - `store`
      Creates a store credit note.
      
      **Prerequisites**
      
      -   The `invoice.status` must be `paid`, `payment_due`, `posted`, or `not_paid`.

- `reason_code` (optional, enumerated string)
  The reason for issuing this Credit Note. The following reason codes are supported now\[Deprecated; use the [create\_reason\_code](/docs/api/credit_notes/credit_note-object#create_reason_code) parameter instead\].
  Possible enum values:
    - `product_unsatisfactory`
      Product Unsatisfactory
    - `service_unsatisfactory`
      Service Unsatisfactory
    - `order_change`
      Order Change
    - `order_cancellation`
      Order Cancellation
    - `waiver`
      Waiver
    - `other`
      Can be set when none of the above reason codes are applicable

- `create_reason_code` (optional, string, max chars=100)
  Reason code for creating the credit note.
  
  **Constraints**
  
  -   Must be one of the case-sensitive [reason codes](https://www.chargebee.com/docs/billing/2.0/site-configuration/reason-codes#managing-reason-codes-for-credit-notes) set in Chargebee Billing.
  
  **Required when**
  
  -   Reason codes are configured as mandatory on the site.

- `date` (optional, timestamp(UTC) in seconds)
  The date on which the credit note is issued.
  
  **Constraints**
  
  -   Must be on or after the `invoice.date` and cannot be a future date.

- `customer_notes` (optional, string, max chars=2000)
  A note to be added for this operation, to the credit note. This note is displayed on customer-facing documents such as the [Credit Note PDF](/docs/api/credit_notes/retrieve-credit-note-as-pdf) .

- `currency_code` (required if Multicurrency is enabled, string, max chars=3)
  The currency code (ISO 4217 format) for the credit note. It is required for a standalone credit note if Multicurrency is enabled.

- `comment` (optional, string, max chars=300)
  An internal [comment](/docs/api/comments) to be added for this operation, to the credit note. 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 [Credit Note PDF](/docs/api/credit_notes/retrieve-credit-note-as-pdf) .

- `line_items` (optional, array)
  Parameters for line\_items
  - `reference_line_item_id` (optional, string, max chars=40)
    Uniquely identifies a line\_item
  - `unit_amount` (optional, in cents)
    Unit amount of the line item. Required for FLAT\_FEE, PER\_UNIT and VOLUME pricing model.
  - `unit_amount_in_decimal` (optional, string, max chars=39)
    The decimal representation of the unit amount of the `line_item`. The value is in major units of the currency. Applicable for the line\_item when the `pricing_model` is `flat_fee` , `per_unit` or `volume`. Can be provided only when [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `quantity` (optional, integer)
    Quantity of the line item. Required for PER\_UNIT and VOLUME pricing model.
  - `quantity_in_decimal` (optional, string, max chars=33)
    The decimal representation of the quantity of the `line_item`. Applicable for the `line_item` when the `pricing_model` is `per_unit` and `volume`. Can be provided only when [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `amount` (optional, in cents)
    Amount of the line item. Applicable only for STAIRSTEP, TIERED pricing\_model.
  - `date_from` (optional, timestamp(UTC) in seconds)
    Start date of this line item.
  - `date_to` (optional, timestamp(UTC) in seconds)
    End date of this line item.
  - `description` (optional, string, max chars=250)
    Description for the line item.
  - `entity_type` (optional, enumerated string)
    Possible enum values:
      - `adhoc`
        Indicates that this line item is not modelled; that is, it was created ad hoc. The `entity_id` attribute is `null` in this case.
      - `plan_item_price`
        Indicates that this line item is based on a plan item price.
      - `addon_item_price`
        Indicates that this line item is based on an addon item price.
      - `charge_item_price`
        Indicates that this line item is based on a charge item price.
  - `entity_id` (optional, string, max chars=100)

## Returns

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

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