# Export invoices

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


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

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

This API triggers export of invoice data. The exported zip file contains CSV files with invoice-related data.

### Invoice Export Best Practice[](#invoice-export-best-practice)

For a full export, Chargebee recommends exporting data in batches by using date filters. The table below provides examples of how to set the filters:

**Scenario**

**Filter Example**

**Description**

Export invoices updated after January 1, 2024

_invoice\[updated\_at\]\[after\] = "1704067200"_

Export invoices from January 1, 2024 onwards.

Export invoices for 2023

_invoice\[updated\_at\]\[between\] = "\[1672531200,1704067199\]"_

Export all invoices for the year 2023.

Export invoices for 2022

_invoice\[updated\_at\]\[between\] = "\[1640995200,1672531199\]"_

Export all invoices for the year 2022.

If the export still fails, further reduce the date range, for example:

**Scenario**

**Filter Example**

**Description**

Export for the second half of 2024

_invoice\[updated\_at\]\[after\] = "1717200000"_

Export invoices are updated after June 1, 2024.

Export for the first half of 2024

_invoice\[updated\_at\]\[between\] = "\[1704067200,1717199999\]"_

Export invoices updated between January 1, 2024, and May 31, 2024.

Export for the second half of 2023

_invoice\[updated\_at\]\[between\] = "\[1685577600,1704067199\]"_

Export invoices updated between June 1, 2023, and December 31, 2023.

Export for the first half of 2023

_invoice\[updated\_at\]\[between\] = "\[1672531200,1685577599\]"_

Export invoices updated between January 1, 2023, and May 31, 2023.

**Note**

The date ranges in the examples above are just suggestions; you can adjust the date window to fit your specific needs. If an export fails due to large data volume, reduce the date window further and retry the export.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/exports/invoices \
     -u {site_api_key}:\
     -d "invoice[status][is_not]"="PAID" \
     -d "invoice[total][lte]"="1000"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Export.Invoices()
		.InvoiceStatus().IsNot(Invoice.StatusEnum.Paid)
		.InvoiceTotal().Lte(1000)
		.Request();

Export export = result.Export;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    "github.com/chargebee/chargebee-go/v3/filter"
    exportAction "github.com/chargebee/chargebee-go/v3/actions/export"
    "github.com/chargebee/chargebee-go/v3/models/export"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := exportAction.Invoices(&export.InvoicesRequestParams{
        Invoice : &export.InvoicesInvoiceParams{
            Status : &filter.EnumFilter{
                IsNot : "paid",
            },
            Total : &filter.NumberFilter{
                Lte : 1000,
            },
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Export := res.Export
    }
}
```

#### 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.ExportInvoicesRequest{
    Invoice : &chargebee.ExportInvoicesInvoice{
        Status : &chargebee.EnumFilter{
            IsNot : "paid",
        },
        Total : &chargebee.NumberFilter{
            Lte : 1000,
        },
    },
}
  res, err := client.Export.Invoices(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Export := res.Export
    }
}
```

#### 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 = Export.invoices().invoiceStatus().isNot(Invoice.Status.PAID).invoiceTotal().lte(1000L).request();

        Export export = result.export();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.export.Export;
import com.chargebee.v4.models.export.params.ExportInvoicesParams;
import com.chargebee.v4.models.export.responses.ExportInvoicesResponse;

public class ExportInvoices {

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

        ExportInvoicesParams.InvoiceParams invoice =
            ExportInvoicesParams.InvoiceParams.builder()
                .status()
                .isNot(ExportInvoicesParams.InvoiceParams.Status.PAID)
                .total()
                .lte(1000L)
                .build();

        ExportInvoicesParams params = ExportInvoicesParams.builder()
            .invoice(invoice)
            .build();

        ExportInvoicesResponse response = client.exports().invoices(params);

        Export export = response.getExport();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.export.invoices({
        invoice: {
            status: {
                is_not: "paid"
            },
            total: {
                lte: 1000
            }
        }
    });

    console.log(result);
    const export_response = result.export;
} 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->export()->invoices([
    "invoice" => [
        "status" => [
            "is_not" => "paid"
        ],
        "total" => [
            "lte" => 1000
        ]
    ]
]);
$export = $result->export;
```

#### Python

```python
import chargebee
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Export.invoices(
    cb_client.Export.InvoicesParams(
        invoice=cb_client.Export.InvoicesInvoiceParams(
            status=Filters.EnumFilter(IS_NOT=chargebee.Invoice.Status.PAID),
            total=Filters.NumberFilter(LTE="1000")
        )
    )
)
export = response.export
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Export.invoices({
  "invoice[status][is_not]" => "paid",
  "invoice[total][lte]" => 1000
})

export = result.export
```

## Sample Response

```json
{
  "export": {
    "created_at": 1527791400,
    "id": "__test__KyVnHhSBWTCX18q",
    "mime_type": "zip",
    "object": "export",
    "operation_type": "Invoices",
    "status": "in_process"
  }
}
```

## URL Format

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

## Input Parameters

- `payment_owner` (optional, string)
  optional, string filter
  
  Payment owner of an invoice. **Supported operators :** is, is\_not, starts\_with, in, not\_in
  
  **Example →** _payment\_owner\[is\] = "payment\_customer"_

- `invoice` (optional, string)
  Parameters for invoice
  - `id` (optional, string)
    The invoice number. Acts as a identifier for invoice and typically generated sequentially.
  - `subscription_id` (optional, string)
    To filter based on subscription\_id. NOTE: Not to be used if _consolidated invoicing_ is enabled.
  - `customer_id` (optional, string)
    The identifier of the customer this invoice belongs to.
  - `recurring` (optional, enumerated string)
    Boolean indicating whether this invoice belongs to a subscription
  - `status` (optional, enumerated string)
    Current status of this invoice.
  - `price_type` (optional, enumerated string)
    The price type of the invoice.
  - `total` (optional, number)
    Invoiced amount displayed in cents; that is, a decimal point is not present between the whole number and the decimal part. For example, $499.99 is displayed as 49999, and so on.
  - `amount_paid` (optional, number)
    Payments collected successfully for the invoice. This is the sum of `[linked_payments[].txn_amount](/docs/api/invoices/invoice-object#linked_payments)` for all `linked_payments[]` that have `txn_status` as `success`.
  - `amount_adjusted` (optional, number)
    Total adjustments made against this invoice.
  - `credits_applied` (optional, number)
    Total credits applied against this invoice.
  - `amount_due` (optional, number)
    The unpaid amount that is due on the invoice. This is calculated as: `[total](/docs/api/invoices/invoice-object#total)`
    
    -   `[amount_paid](/docs/api/invoices/invoice-object#amount_paid)`
    -   sum of `[applied_credits](/docs/api/invoices/invoice-object#applied_credits).applied_amount`
    -   sum of `[adjustment_credit_notes](/docs/api/invoices/invoice-object#adjustment_credit_notes).cn_total`
    -   sum of `[linked_taxes_withheld](/docs/api/invoices/invoice-object#linked_taxes_withheld).amount`.
  - `dunning_status` (optional, enumerated string)
    Current dunning status of the invoice.
  - `channel` (optional, enumerated string)
    The subscription channel this object originated from and is maintained in.
  - `date` (optional, timestamp(UTC) in seconds)
    The document date displayed on the invoice PDF.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)
  - `paid_at` (optional, timestamp(UTC) in seconds)
    Timestamp indicating the date & time this invoice got paid.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)
  - `updated_at` (optional, timestamp(UTC) in seconds)
    To filter based on `updated_at`. This attribute will be present only if the resource has been updated after 2016-09-28. It is advisable when using this filter, to pass the `sort_by` input parameter as `updated_at` for a faster response. [Learn more](/docs/api/exports) about the best practice before performing full export.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)

## Returns

- `export` (Export object)
  Resource object representing export
