# List coupon codes

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


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

List the available coupon codes.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/coupon_codes \
     -G  \
     -u {site_api_key}:\
     --data-urlencode limit=2
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = CouponCode.List()
		.Limit(2)
		.Request();

foreach (var listItem in result.List){
  CouponCode couponCode = listItem.CouponCode;
}
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    couponcodeAction "github.com/chargebee/chargebee-go/v3/actions/couponcode"
    "github.com/chargebee/chargebee-go/v3/models/couponcode"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := couponcodeAction.List(&couponcode.ListRequestParams{
        Limit : chargebee.Int32(2),
    }).ListRequest()
    if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            CouponCode := res.List[idx].CouponCode
        }
    }
}
```

#### 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.CouponCodeListRequest{
    Limit : chargebee.Int32(2),
}
  res, err := client.CouponCode.List(req)
      if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            CouponCode := res.List[idx].CouponCode
        }
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
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 = CouponCode.list()
            .limit(2)
            .request();

        for (ListResult.Entry entry : result) {
            CouponCode couponCode = entry.couponCode();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.couponCode.CouponCode;
import com.chargebee.v4.models.couponCode.params.CouponCodeListParams;
import com.chargebee.v4.models.couponCode.responses.CouponCodeListResponse;
import java.util.List;

public class CouponCodeList {

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

        CouponCodeListParams params = CouponCodeListParams.builder()
            .limit(2)
            .build();

        CouponCodeListResponse response = client.couponCodes().list(params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.couponCode.list({
        limit: 2
    });
    result.list.forEach((entry) => {
        console.log(entry);
        const couponCode = entry.coupon_code;
    });
} 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->couponCode()->all([
    "limit" => 2
]);
foreach($result->list as $entry) {
    $couponCode = $entry->coupon_code;
}
```

#### Python

```python
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.CouponCode.list(
    cb_client.CouponCode.ListParams(
        limit=2
    )
)
for entry in entries.list:
    coupon_code = entry.coupon_code
```

#### Ruby

```ruby
require 'chargebee'

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

list = ChargeBee::CouponCode.list({
  :limit => 2
})

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

## Sample Response

```json
{
  "list": [
    {
      "coupon_code": {
        "code": "CBC090A",
        "coupon_id": "beta",
        "coupon_set_id": "cs_3RtyuMoOn",
        "coupon_set_name": "Launch Promotion",
        "object": "coupon_code",
        "status": "not_redeemed"
      }
    },
    {..}
  ],
  "next_offset": "[\"155000000004\"]"
}
```

## URL Format

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

## 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_code` (Coupon code object)
  Resource object representing coupon\_code
