# List discounts for a subscription

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


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

Retrieves a list of `[discount](/docs/api/discounts)` resources [currently attached](/docs/api/subscriptions/subscription-object#discounts) to a specific subscription. The list is sorted in descending order based on the `[created_at](/docs/api/discounts/discount-object#created_at)` timestamp.

**Note** This endpoint does not return `[coupon](/docs/api/coupons)` or `[coupon_code](/docs/api/coupon_codes)` resources.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8at0iSK6IPu41q/discounts \
     -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 = Subscription.ListDiscounts("__test__8at0iSK6IPu41q")
		.Limit(2)
		.Request();

foreach (var listItem in result.List){
  Discount discount = listItem.Discount;
}
```

#### Go

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

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

#### 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 = Subscription.listDiscounts("__test__8at0iSK6IPu41q")
            .limit(2)
            .request();

        for (ListResult.Entry entry : result) {
            Discount discount = entry.discount();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.discount.Discount;
import com.chargebee.v4.models.subscription.params.SubscriptionListDiscountsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionListDiscountsResponse;
import java.util.List;

public class SubscriptionListDiscounts {

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

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

        SubscriptionListDiscountsResponse response = client
            .subscriptions()
            .listDiscounts("__test__8at0iSK6IPu41q", params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

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

#### Python

```python
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.Subscription.list_discounts("__test__8at0iSK6IPu41q",
    cb_client.Subscription.ListDiscountsParams(
        limit=2
    )
)
for entry in entries.list:
    discount = entry.discount
```

#### Ruby

```ruby
require 'chargebee'

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

list = ChargeBee::Subscription.list_discounts("__test__8at0iSK6IPu41q",{
  :limit => 2
})

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

## Sample Response

```json
{
  "list": [
    {
      "discount": {
        "amount": 100,
        "applied_count": 1,
        "apply_on": "invoice_amount",
        "created_at": 1608822300,
        "currency_code": "USD",
        "duration_type": "forever",
        "id": "__test__8at0iSK6IPuW1r",
        "invoice_name": "__test__8at0iSK6IPuW1r",
        "object": "discount",
        "type": "fixed_amount"
      }
    },
    {..}
  ]
}
```

## URL Format

**GET** https://[site].chargebee.com/api/v2/subscriptions/{subscription-id}/discounts

## 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`.

- `discount` (Discount object)
  Resource object representing discount
