# Download e-invoice

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


[Strongly Consistent](/docs/api/read-consistency)

Download the e-invoice 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-invoice/tree/).

**Note**

-   You can only download e-invoices when their `status` is `success`.
-   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-invoice/cac-AdditionalDocumentReference/cac-Attachment/cbc-EmbeddedDocumentBinaryObject/)`, which is the Base64-encoded version of the PDF.

## Sample Request

#### Chargebee CLI

```bash
chargebee invoice download-einvoice __demo_inv__1
```

#### cURL

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

#### .NET

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

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

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

#### 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.DownloadEinvoice("__demo_inv__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.InvoiceDownloadEinvoiceRequest{
    Id : "__demo_inv__1",
}
  res, err := client.Invoice.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 = Invoice.downloadEinvoice("__demo_inv__1").request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.download.Download;
import com.chargebee.v4.models.invoice.params.DownloadEinvoiceParams;
import com.chargebee.v4.models.invoice.responses.DownloadEinvoiceResponse;
import java.util.List;

public class DownloadEinvoice {

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

        DownloadEinvoiceResponse response = client.invoices().downloadEinvoice("__demo_inv__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.invoice.downloadEinvoice("__demo_inv__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->invoice()->downloadEinvoice("__demo_inv__1");
$downloads = $result->downloads;
```

#### Python

```python
from chargebee import Chargebee

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

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.download_einvoice("__demo_inv__1")

downloads = result.downloads
```

## Sample Response

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

## URL Format

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

## Returns

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