# Download e-invoice for credit note

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


Download the e-invoice for the credit note in both XML and PDF formats. The response consists of a `download` object for each format. The XML format follows the [structure as per Peppol BIS Billing v3.0](https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-creditnote/tree/).

**Note**

-   You can only download e-invoices when their `status` is `success` or `registered`.
-   There are some cases in which the PDF is not available for download. In such cases, you can obtain it from the XML by decoding the value for `[cbc:EmbeddedDocumentBinaryObject](https://docs.peppol.eu/poacc/billing/3.0/syntax/ubl-creditnote/cac-AdditionalDocumentReference/cac-Attachment/cbc-EmbeddedDocumentBinaryObject/)`, which is the Base64-encoded version of the PDF.

## Sample Request

#### cURL

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

#### .NET

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

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

List<Download> downloads = result.Downloads;
```

#### 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.DownloadEinvoice("__demo_cn__1").Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Downloads := res.Downloads
    }
}
```

#### 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.CreditNoteDownloadEinvoiceRequest{
    Id : "__demo_cn__1",
}
  res, err := client.CreditNote.DownloadEinvoice(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Downloads := res.Downloads
    }
}
```

#### Java

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

public class Sample {

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

        List<Download> downloads = result.downloads();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.params.CreditNoteDownloadEinvoiceParams;
import com.chargebee.v4.models.creditNote.responses.CreditNoteDownloadEinvoiceResponse;
import com.chargebee.v4.models.download.Download;
import java.util.List;

public class CreditNoteDownloadEinvoice {

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

        CreditNoteDownloadEinvoiceResponse response = client.creditNotes().downloadEinvoice("__demo_cn__1");

        List<Download> downloads = response.getDownloads();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.creditNote.downloadEinvoice("__demo_cn__1");

    console.log(result);
    const downloads = result.downloads;
} 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()->downloadEinvoice("__demo_cn__1");
$downloads = $result->downloads;
```

#### Python

```python
from chargebee import Chargebee

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

#### Ruby

```ruby
require 'chargebee'

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

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

downloads = result.downloads
```

## Sample Response

```json
{
  "downloads": [
    {
      "download_url": "https://dj-temp.s3.eu-west-1.amazonaws.com/596b46e3f21011b29678bc15f5c938075755c163ae4fdb15b98f3e8e5ca6eab7cf16afc6c788b29f91e6362a7aae4867ba4153eef2838556ee541ba85af09369?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAI5G5MTYS7SBP4ZEQ%2F20211123%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20211123T070845Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=4d99603c2f7bcdd6cf450a27372ee2f95003afb64a0188b4ebe142a403e14acf",
      "mime_type": "application/xml",
      "object": "download",
      "valid_till": 1638236325
    },
    {..}
  ]
}
```

## URL Format

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

## Returns

- `downloads` (always returned)
  Resource object representing download
