# List coupons

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


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

**Important**  
For sites where both [legacy and latest](/docs/api/v2/pcv-1/upgrade#retrieving-api-responses-in-latest-api-format) product catalog versions are active, GET API requests return responses in a `compat` format by default. This format works with both latest and legacy Product Catalog.

**Override options:**

-   `chargebee-response-schema-type: items` → Return response in latest product catalog format only.
-   `chargebee-response-schema-type: plans_addons` → Return response in legacy product catalog format only.

List all the available coupons that are created for a specific promotion or offers. You can find list of coupon codes that are currently active, expired, archived or deleted.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/coupons \
     -G  \
     -u {site_api_key}:\
     --data-urlencode limit=5 \
     --data-urlencode "duration_type[is]"="FOREVER" \
     --data-urlencode "status[is]"="ACTIVE" \
     --data-urlencode "sort_by[asc]"="created_at"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = Coupon.List()
		.Limit(5)
		.DurationType().Is(Coupon.DurationTypeEnum.Forever)
		.Status().Is(Coupon.StatusEnum.Active)
		.SortByCreatedAt(SortOrderEnum.Asc)
		.Request();

foreach (var listItem in result.List){
  Coupon coupon = listItem.Coupon;
}
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    "github.com/chargebee/chargebee-go/v3/filter"
    couponAction "github.com/chargebee/chargebee-go/v3/actions/coupon"
    "github.com/chargebee/chargebee-go/v3/models/coupon"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := couponAction.List(&coupon.ListRequestParams{
        Limit : chargebee.Int32(5),
        DurationType : &filter.EnumFilter{
            Is : "forever",
        },
        Status : &filter.EnumFilter{
            Is : "active",
        },
        SortBy : &filter.SortFilter{
            Asc : "created_at",
        },
    }).ListRequest()
    if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            Coupon := res.List[idx].Coupon
        }
    }
}
```

#### 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.CouponListRequest{
    Limit : chargebee.Int32(5),
    DurationType : &chargebee.EnumFilter{
        Is : "forever",
    },
    Status : &chargebee.EnumFilter{
        Is : "active",
    },
    SortBy : &chargebee.SortFilter{
        Asc : "created_at",
    },
}
  res, err := client.Coupon.List(req)
      if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            Coupon := res.List[idx].Coupon
        }
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.filters.enums.SortOrder;
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}");
        ListResult result = Coupon.list()
            .limit(5)
            .durationType().is(Coupon.DurationType.FOREVER)
            .status().is(Coupon.Status.ACTIVE)
            .sortByCreatedAt(SortOrder.ASC)
            .request();

        for (ListResult.Entry entry : result) {
            Coupon coupon = entry.coupon();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.coupon.Coupon;
import com.chargebee.v4.models.coupon.params.CouponListParams;
import com.chargebee.v4.models.coupon.responses.CouponListResponse;
import java.util.List;

public class CouponList {

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

        CouponListParams params = CouponListParams.builder()
            .limit(5)
            .durationType()
            .is(CouponListParams.DurationType.FOREVER)
            .status()
            .is(CouponListParams.Status.ACTIVE)
            .sortBy()
            .created_at()
            .asc()
            .build();

        CouponListResponse response = client.coupons().list(params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.coupon.list({
        limit: 5,
        duration_type: {
            is: "forever"
        },
        status: {
            is: "active"
        },
        "sort_by[asc]": "created_at"
    });
    result.list.forEach((entry) => {
        console.log(entry);
        const coupon = entry.coupon;
    });
} 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->coupon()->all([
    "limit" => 5,
    "duration_type" => [
        "is" => "forever"
    ],
    "status" => [
        "is" => "active"
    ],
    "sort_by" => [
        "asc" => "created_at"
    ]
]);
foreach($result->list as $entry) {
    $coupon = $entry->coupon;
}
```

#### Python

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

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.Coupon.list(
    cb_client.Coupon.ListParams(
        limit=5,
        duration_type=Filters.EnumFilter(IS=chargebee.Coupon.DurationType.FOREVER),
        status=Filters.EnumFilter(IS=chargebee.Coupon.Status.ACTIVE),
        sort_by=Filters.SortFilter(ASC="created_at")
    )
)
for entry in entries.list:
    coupon = entry.coupon
```

#### Ruby

```ruby
require 'chargebee'

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

list = ChargeBee::Coupon.list({
  :limit => 5,
  "duration_type[is]" => "forever",
  "status[is]" => "active",
  "sort_by[asc]" => "created_at"
})

list.each do |entry|
  coupon = entry.coupon
end
```

## Sample Response

```json
{
  "list": [
    {
      "coupon": {
        "addon_constraint": "not_applicable",
        "apply_discount_on": "not_applicable",
        "apply_on": "invoice_amount",
        "created_at": 1517505786,
        "currency_code": "USD",
        "discount_amount": 500,
        "discount_type": "fixed_amount",
        "duration_type": "forever",
        "id": "sample_offer",
        "name": "Sample Offer",
        "object": "coupon",
        "plan_constraint": "not_applicable",
        "redemptions": 0,
        "resource_version": 1517505786000,
        "status": "active",
        "updated_at": 1517505786
      }
    },
    {..}
  ]
}
```

## URL Format

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

## Input Parameters

- `limit` (optional, integer, default=10, min=1, max=100)
  The number of resources to be returned.

- `offset` (optional, string, max chars=1000)
  Determines your position in the list for pagination. To ensure that the next page is retrieved correctly, always set `offset` to the value of `next_offset` obtained in the previous iteration of the API call.

## Returns

- `next_offset` (optional, string, max chars=1000)
  This attribute is returned only if more resources are present. To fetch the next set of resources use this value for the input parameter `offset`.

- `coupon` (Coupon object)
  Resource object representing coupon
