# List comments

> 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)

Retrieve the list of comments sorted by the recent ones on the top.

If you want to retrieve the list of comments for an [entity](/docs/api/v2/pcv-1/comments/list-comments), for example, subscription you can filter them by passing the entity type and unique identifier for that entity, for example, subscription ID.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/comments \
     -G  \
     -u {site_api_key}:\
     --data-urlencode limit=2 \
     --data-urlencode "sort_by[asc]"="created_at"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = Comment.List()
		.Limit(2)
		.SortByCreatedAt(SortOrderEnum.Asc)
		.Request();

foreach (var listItem in result.List){
  Comment comment = listItem.Comment;
}
```

#### Go

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

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

#### 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 = Comment.list()
            .limit(2)
            .sortByCreatedAt(SortOrder.ASC)
            .request();

        for (ListResult.Entry entry : result) {
            Comment comment = entry.comment();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.comment.Comment;
import com.chargebee.v4.models.comment.params.CommentListParams;
import com.chargebee.v4.models.comment.responses.CommentListResponse;
import java.util.List;

public class CommentList {

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

        CommentListParams params = CommentListParams.builder()
            .limit(2)
            .sortBy()
            .created_at()
            .asc()
            .build();

        CommentListResponse response = client.comments().list(params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

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

#### Python

```python
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.Comment.list(
    cb_client.Comment.ListParams(
        limit=2,
        sort_by=Filters.SortFilter(ASC="created_at")
    )
)
for entry in entries.list:
    comment = entry.comment
```

#### Ruby

```ruby
require 'chargebee'

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

list = ChargeBee::Comment.list({
  :limit => 2,
  "sort_by[asc]" => "created_at"
})

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

## Sample Response

```json
{
  "list": [
    {
      "comment": {
        "added_by": "full_access_key_v1",
        "created_at": 1517505963,
        "entity_id": "__test__KyVnHhSBWm65N2rx",
        "entity_type": "subscription",
        "id": "cmt___test__KyVnHhSBWm69N2s4",
        "notes": "This is a test comment",
        "object": "comment",
        "type": "user"
      }
    },
    {..}
  ],
  "next_offset": "[\"1517505966000\",\"109000000148\"]"
}
```

## URL Format

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

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

- `entity_type` (optional, enumerated string)
  Type of the entity this comment generated for.
  Possible enum values:
    - `customer`
    - `subscription`
    - `invoice`
    - `quote`
    - `credit_note`
    - `transaction`
    - `plan`
    - `addon`
    - `coupon`
    - `order`
    - `business_entity`

- `entity_id` (optional, string, max chars=100)
  Unique identifier of the entity.

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

- `comment` (Comment object)
  Resource object representing comment
