# Export coupons

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

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/exports/coupons \
     -u {site_api_key}:\
     -d "coupon[duration_type][is]"="FOREVER" \
     -d "coupon[status][is_not]"="ACTIVE"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Export.Coupons()
		.CouponDurationType().Is(Coupon.DurationTypeEnum.Forever)
		.CouponStatus().IsNot(Coupon.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.Coupons(&export.CouponsRequestParams{
        Coupon : &export.CouponsCouponParams{
            DurationType : &filter.EnumFilter{
                Is : "forever",
            },
            Status : &filter.EnumFilter{
                IsNot : "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.ExportCouponsRequest{
    Coupon : &chargebee.ExportCouponsCoupon{
        DurationType : &chargebee.EnumFilter{
            Is : "forever",
        },
        Status : &chargebee.EnumFilter{
            IsNot : "active",
        },
    },
}
  res, err := client.Export.Coupons(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.coupons().couponDurationType().is(Coupon.DurationType.FOREVER).couponStatus().isNot(Coupon.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.ExportCouponsParams;
import com.chargebee.v4.models.export.responses.ExportCouponsResponse;

public class ExportCoupons {

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

        ExportCouponsParams.CouponParams coupon =
            ExportCouponsParams.CouponParams.builder()
                .durationType()
                .is(ExportCouponsParams.CouponParams.DurationType.FOREVER)
                .status()
                .isNot(ExportCouponsParams.CouponParams.Status.ACTIVE)
                .build();

        ExportCouponsParams params = ExportCouponsParams.builder()
            .coupon(coupon)
            .build();

        ExportCouponsResponse response = client.exports().coupons(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.coupons({
        coupon: {
            duration_type: {
                is: "forever"
            },
            status: {
                is_not: "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()->coupons([
    "coupon" => [
        "duration_type" => [
            "is" => "forever"
        ],
        "status" => [
            "is_not" => "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.coupons(
    cb_client.Export.CouponsParams(
        coupon=cb_client.Export.CouponsCouponParams(
            duration_type=Filters.EnumFilter(IS=chargebee.Coupon.DurationType.FOREVER),
            status=Filters.EnumFilter(IS_NOT=chargebee.Coupon.Status.ACTIVE)
        )
    )
)
export = response.export
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Export.coupons({
  "coupon[duration_type][is]" => "forever",
  "coupon[status][is_not]" => "active"
})

export = result.export
```

## Sample Response

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

## URL Format

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

## Input Parameters

- `currency_code` (optional, string)
  optional, string filter
  
  The currency code ([ISO 4217 format](https://www.chargebee.com/docs/supported-currencies.html) ) of the coupon. Applicable for _fixed\_amount_ coupons alone. **Supported operators :** is, is\_not, starts\_with, in, not\_in
  
  **Example →** _currency\_code\[is\] = "USD"_

- `applicable_item_price_ids` (optional, string)
  optional, string filter
  
  List of itemPrice ids for which these coupons are applicable.
  
  **Supported operators :** in, is
  
  **Example →** _applicable\_item\_price\_ids\[in\] = "day-pass-USD"_

- `coupon` (optional, string)
  Parameters for coupon
  - `id` (optional, string)
    Used to uniquely identify the coupon in your website/application and to integrate with Chargebee.
    
    **Note:**
    
    When the coupon ID contains a special character; for example: `#`, the API returns an error. Make sure that you [encode](https://www.urlencoder.org/) the coupon ID in the path parameter before making an API call.
  - `name` (optional, string)
    The display name used in web interface for identifying the coupon.
    
    **Note:**
    
    When the name of the coupon set contains a special character; for example: `#`, the API returns an error. Make sure that you [encode](https://www.urlencoder.org/) the name of the coupon set in the path parameter before making an API call.
  - `discount_type` (optional, enumerated string)
    The type of deduction
  - `duration_type` (optional, enumerated string)
    Specifies the time duration for which this coupon is attached to the subscription.
  - `status` (optional, enumerated string)
    Status of the coupon.
  - `apply_on` (optional, enumerated string)
    The amount on the invoice to which the coupon is applied.
  - `created_at` (optional, timestamp(UTC) in seconds)
    Timestamp indicating when this coupon is created.
    - `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-11-09.
    - `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
