# Retrieve usages for an invoice as PDF

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


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

**Advanced Usage-Based Billing**

For high-scale usage ingestion, use [Advanced Usage-Based Billing](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/understanding-usages) with the [Usage Events API](/docs/api/usage_events). The Usage Events API supports schemaless event ingestion at scale, including [individual events](/docs/api/usage_events/create-a-usage-event), [batch ingestion](/docs/api/usage_events/ingest-usages-in-batch), and [usage file ingestion](/docs/api/usage_files/usage-file-object).

Retrieves usages record for an invoice in PDF file format. This endpoint is part of the [Usages API](/docs/api/usages) for **Automated Metered Billing**.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/usages/pdf \
     -u {site_api_key}:\
     -d "invoice[id]"="__demo_inv__1" \
     -d disposition_type="INLINE"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Usage.Pdf()
		.InvoiceId("__demo_inv__1")
		.DispositionType(DispositionTypeEnum.Inline)
		.Request();

Download download = result.Download;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    usageAction "github.com/chargebee/chargebee-go/v3/actions/usage"
    "github.com/chargebee/chargebee-go/v3/models/usage"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := usageAction.Pdf(&usage.PdfRequestParams{
        Invoice : &usage.PdfInvoiceParams{
            Id : "__demo_inv__1",
        },
        DispositionType : enum.DispositionTypeInline,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Download := res.Download
    }
}
```

#### 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.UsagePdfRequest{
    Invoice : &chargebee.UsagePdfInvoice{
        Id : "__demo_inv__1",
    },
    DispositionType : chargebee.DispositionTypeInline,
}
  res, err := client.Usage.Pdf(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Download := res.Download
    }
}
```

#### 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 = Usage.pdf()
            .invoiceId("__demo_inv__1")
            .dispositionType(DispositionType.INLINE)
            .request();

        Download download = result.download();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.download.Download;
import com.chargebee.v4.models.usage.params.UsagePdfParams;
import com.chargebee.v4.models.usage.responses.UsagePdfResponse;

public class UsagePdf {

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

        UsagePdfParams.InvoiceParams invoiceParams =
            UsagePdfParams.InvoiceParams.builder()
                .id("__demo_inv__1")
                .build();

        UsagePdfParams params = UsagePdfParams.builder()
            .invoice(invoiceParams)
            .dispositionType(UsagePdfParams.DispositionType.INLINE)
            .build();

        UsagePdfResponse response = client.usages().pdf(params);

        Download download = response.getDownload();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.usage.pdf({
        invoice: {
            id: "__demo_inv__1"
        },
        disposition_type: "inline"
    });

    console.log(result);
    const download = result.download;
} 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->usage()->pdf([
    "invoice" => [
        "id" => "__demo_inv__1"
    ],
    "disposition_type" => "inline"
]);
$download = $result->download;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Usage.pdf(
    cb_client.Usage.PdfParams(
        invoice=cb_client.Usage.PdfInvoiceParams(
            id="__demo_inv__1"
        ),
        disposition_type=chargebee.DispositionType.INLINE
    )
)
download = response.download
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Usage.pdf({
  :invoice => {
    :id => "__demo_inv__1"
  },
  :disposition_type => "INLINE"
})

download = result.download
```

## Sample Response

```json
{
  "download": {
    "download_url": "https://cb-local-downloads.s3.amazonaws.com/yourapp/usage/__test__KyVnOySLTs2AP27.pdf?response-content-disposition=inline%3Bfilename%3Dyourapp%2Fusage%2F__test__KyVnOySLTs2AP27.pdf&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20210108T061943Z&X-Amz-SignedHeaders=host&X-Amz-Expires=599&X-Amz-Credential=AKIAJI4SN7ONHAOGLOGA%2F20210108%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=3648b8dadb4fcafea3375bf5f9b116e5cbdb295b8428965810b6533417b04b88",
    "object": "download",
    "valid_till": 1610087383
  }
}
```

## URL Format

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

## Input Parameters

- `disposition_type` (optional, enumerated string, default=attachment)
  Determines the pdf should be rendered as inline or attachment in the browser.
  Possible enum values:
    - `attachment`
      PDF is rendered as attachment in the browser
    - `inline`
      PDF is rendered as inline in the browser

- `invoice` (optional, string)
  Parameters for invoice
  - `id` (required, string, max chars=50)
    The invoice number. Acts as a identifier for invoice and typically generated sequentially.

## Returns

- `download` (Download object)
  Resource object representing download
