# Export subscriptions

> 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 subscription data. The exported zip file contains CSV files with subscription-related data.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/exports/subscriptions \
     -u {site_api_key}:\
     -d "subscription[status][is]"="ACTIVE"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Export.Subscriptions()
		.SubscriptionStatus().Is(Subscription.StatusEnum.Active)
		.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.Subscriptions(&export.SubscriptionsRequestParams{
        Subscription : &export.SubscriptionsSubscriptionParams{
            Status : &filter.EnumFilter{
                Is : "active",
            },
        },
    }).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.ExportSubscriptionsRequest{
    Subscription : &chargebee.ExportSubscriptionsSubscription{
        Status : &chargebee.EnumFilter{
            Is : "active",
        },
    },
}
  res, err := client.Export.Subscriptions(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.subscriptions().subscriptionStatus().is(Subscription.Status.ACTIVE).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.ExportSubscriptionsParams;
import com.chargebee.v4.models.export.responses.ExportSubscriptionsResponse;

public class ExportSubscriptions {

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

        ExportSubscriptionsParams.SubscriptionParams subscription =
            ExportSubscriptionsParams.SubscriptionParams.builder()
                .status()
                .is(ExportSubscriptionsParams.SubscriptionParams.Status.ACTIVE)
                .build();

        ExportSubscriptionsParams params = ExportSubscriptionsParams.builder()
            .subscription(subscription)
            .build();

        ExportSubscriptionsResponse response = client.exports().subscriptions(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.subscriptions({
        subscription: {
            status: {
                is: "active"
            }
        }
    });

    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()->subscriptions([
    "subscription" => [
        "status" => [
            "is" => "active"
        ]
    ]
]);
$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.subscriptions(
    cb_client.Export.SubscriptionsParams(
        subscription=cb_client.Export.SubscriptionsSubscriptionParams(
            status=Filters.EnumFilter(IS=chargebee.Subscription.Status.ACTIVE)
        )
    )
)
export = response.export
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Export.subscriptions({
  "subscription[status][is]" => "active"
})

export = result.export
```

## Sample Response

```json
{
  "export": {
    "created_at": 1612968382,
    "id": "__test__8aszcSOcsxFR7t",
    "mime_type": "zip",
    "object": "export",
    "operation_type": "Subscriptions",
    "status": "in_process"
  }
}
```

## URL Format

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

## Input Parameters

- `export_type` (optional, enumerated string, default=data)
  Determines the format of the data. Returns the export type based on the selected value.
  Possible enum values:
    - `data`
      Provides the full set of data for the subscriptions in multiple `.csv` files.
    - `import_friendly_data`
      Provides a `.csv` file whose columns match the [`subscription`](/docs/api/subscriptions/subscription-object) schema. This file format can be readily imported through the UI by using [Bulk Operations](https://www.chargebee.com/docs/bulk-operations.html).

- `item_id` (optional, string)
  optional, string filter
  
  The plan item code. **Supported operators :** is, is\_not, starts\_with, in, not\_in
  
  **Example →** _item\_id\[is\] = "silver"_

- `item_price_id` (optional, string)
  optional, string filter
  
  The plan item price code. **Supported operators :** is, is\_not, starts\_with, in, not\_in
  
  **Example →** _item\_price\_id\[is\] = "silver-USD-monthly"_

- `cancel_reason_code` (optional, string)
  optional, string filter
  
  Reason code for canceling the subscription. Must be one from a list of reason codes set in the Chargebee app in **Settings > Configure Chargebee > Reason Codes > Subscriptions > Subscription Cancellation**. Must be passed if set as mandatory in the app. The codes are case-sensitive. **Supported operators :** is, is\_not, starts\_with, in, not\_in
  
  **Example →** _cancel\_reason\_code\[is\] = "Not Paid"_

- `subscription` (optional, string)
  Parameters for subscription
  - `id` (optional, string)
    A unique and immutable identifier for the subscription. If not provided, it is autogenerated.
  - `customer_id` (optional, string)
    Identifier of the customer with whom this subscription is associated.
  - `status` (optional, enumerated string)
    Current state of the subscription
  - `cancel_reason` (optional, enumerated string)
    The reason for canceling the subscription. Set by Chargebee automatically.
  - `remaining_billing_cycles` (optional, number)
    -   When the subscription is not on a contract term: this value is the number of billing cycles remaining after the current cycle, at the end of which, the subscription cancels.
    -   When the subscription is on a [contract term](/docs/api/contract_terms): this value is the number of billing cycles remaining in the contract term after the current billing cycle.
  - `has_scheduled_changes` (optional, enumerated string)
    If `true` , there are subscription changes scheduled on next renewal.
  - `offline_payment_method` (optional, enumerated string)
    The preferred offline payment method for the subscription.
  - `auto_close_invoices` (optional, enumerated string)
    Set to `false` to override for this subscription, the [site-level setting](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/metered_billing#configuring-metered-billing) for auto-closing invoices. Only applicable when auto-closing invoices has been enabled for the site. This attribute has a higher precedence than the same attribute at the [customer level](/docs/api/customers/customer-object#auto_close_invoices) .
  - `channel` (optional, enumerated string)
    The subscription channel this object originated from and is maintained in.
  - `decommissioned` (optional, enumerated string)
    Specifies whether a cancelled subscription is decommissioned or not
  - `created_at` (optional, timestamp(UTC) in seconds)
    The time at which the subscription was created.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)
  - `activated_at` (optional, timestamp(UTC) in seconds)
    Time at which the subscription `status` last changed to `active`. For example, this value is updated when an `in_trial` or `cancelled` subscription activates.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)
  - `next_billing_at` (optional, timestamp(UTC) in seconds)
    The date/time at which the next billing for the subscription happens. This is usually right after `current_term_end` unless multiple subscription terms were invoiced in advance using the `terms_to_charge` parameter.
    - `after` (optional, timestamp(UTC) in seconds)
    - `before` (optional, timestamp(UTC) in seconds)
    - `on` (optional, timestamp(UTC) in seconds)
  - `cancelled_at` (optional, timestamp(UTC) in seconds)
    Time at which subscription was cancelled or is set to be cancelled.
    - `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.
    - `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
