# Send an einvoice for credit notes

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


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

This endpoint is used to send an e-invoice for invoice. To support cases like TDS and invoice edits, we need to stop auto e-invoice sending and be able to send e-invoices manually. This endpoint schedules e-invoices manually. This operation is not allowed when any of the following condition matches:

-   If e-invoicing is not enabled at the site and customer level.
    
-   If there is an e-invoice generated already for the invoice.
    
-   If the **Use automatic e-invoicing** option is selected.
    
-   If there are no generated e-invoices with the `failed` or `skipped` status.
    
-   If the invoice status is `voided` or `pending`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_notes/__demo_cn__1/send_einvoice \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditNote.SendEinvoice("__demo_cn__1").Request();

CreditNote creditNote = result.CreditNote;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    creditnoteAction "github.com/chargebee/chargebee-go/v3/actions/creditnote"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditnoteAction.SendEinvoice("__demo_cn__1").Request()
    if err != nil {
        fmt.Println(err)
    } else {
        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)
  
  res, err := client.CreditNote.SendEinvoice("__demo_cn__1")
      if err != nil {
        fmt.Println(err)
    } else {
        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 = CreditNote.sendEinvoice("__demo_cn__1").request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.creditNote.params.CreditNoteSendEinvoiceParams;
import com.chargebee.v4.models.creditNote.responses.CreditNoteSendEinvoiceResponse;

public class CreditNoteSendEinvoice {

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

        CreditNoteSendEinvoiceResponse response = client.creditNotes().sendEinvoice("__demo_cn__1");

        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.creditNote.sendEinvoice("__demo_cn__1");

    console.log(result);
    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->creditNote()->sendEinvoice("__demo_cn__1");
$creditNote = $result->credit_note;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditNote.send_einvoice("__demo_cn__1")
credit_note = response.credit_note
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::CreditNote.send_einvoice("__demo_cn__1")

credit_note = result.credit_note
```

## Sample Response

```json
{
  "credit_note": {
    "allocations": {},
    "amount_allocated": 0,
    "amount_available": 500,
    "amount_refunded": 0,
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Duncan",
      "last_name": "Walpole",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "channel": "web",
    "create_reason_code": "Product Unsatisfactory",
    "currency_code": "USD",
    "customer_id": "__test__8astSTVO2Rag1",
    "customer_notes": "Products were returned because they were defective",
    "date": 1517504571,
    "deleted": false,
    "exchange_rate": 1,
    "fractional_correction": 0,
    "generated_at": 1517504571,
    "id": "__demo_cn__1",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "einvoice": {
      "id": "HmaT0avT2mtbTL3mR",
      "status": "scheduled",
      "message": "E-invoice sending is scheduled and not yet processed.",
      "object": "einvoice"
    },
    "line_items": [
      {
        "amount": 500,
        "customer_id": "__test__8astSTVO2Rag1",
        "date_from": 1517504571,
        "date_to": 1517504571,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__8astSTVO2TPdG",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "reference_line_item_id": "li___test__8astSTVO2SsQ9",
        "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": 1517504571791,
    "round_off_amount": 0,
    "status": "refund_due",
    "sub_total": 500,
    "taxes": {},
    "total": 500,
    "type": "refundable",
    "updated_at": 1517504571
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/credit_notes/{credit-note-id}/send_einvoice

## Returns

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