# List ledger operations

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


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

Returns a list of operations meeting all the conditions specified in the filter parameters below.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/ledger_operations \
     -G  \
     -u {site_api_key}:\
     --data-urlencode "subscription_id[is]"="1mGETgZVF2umUZq" \
     --data-urlencode "sort_by[desc]"="created_at"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
ListResult result = LedgerOperation.ListLedgerOperations()
		.SubscriptionId().Is("1mGETgZVF2umUZq")
		.SortByCreatedAt(SortOrderEnum.Desc)
		.Request();

foreach (var listItem in result.List){
  LedgerOperation ledgerOperation = listItem.LedgerOperation;
}
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    "github.com/chargebee/chargebee-go/v3/filter"
    ledgeroperationAction "github.com/chargebee/chargebee-go/v3/actions/ledgeroperation"
    "github.com/chargebee/chargebee-go/v3/models/ledgeroperation"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := ledgeroperationAction.ListLedgerOperations(&ledgeroperation.ListLedgerOperationsRequestParams{
        SubscriptionId : &filter.StringFilter{
            Is : "1mGETgZVF2umUZq",
        },
        SortBy : &filter.SortFilter{
            Desc : "created_at",
        },
    }).ListRequest()
    if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            LedgerOperation := res.List[idx].LedgerOperation
        }
    }
}
```

#### 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.LedgerOperationListLedgerOperationsRequest{
    SubscriptionId : &chargebee.StringFilter{
        Is : "1mGETgZVF2umUZq",
    },
    SortBy : &chargebee.SortFilter{
        Desc : "created_at",
    },
}
  res, err := client.LedgerOperation.ListLedgerOperations(req)
      if err != nil {
        fmt.Println(err)
    } else {
        for idx := 0; idx < len(res.List); idx++ {
            LedgerOperation := res.List[idx].LedgerOperation
        }
    }
}
```

#### 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 = LedgerOperation.listLedgerOperations().subscriptionId().is("1mGETgZVF2umUZq").sortByCreatedAt(SortOrder.DESC).request();

        for (ListResult.Entry entry : result) {
            LedgerOperation ledgerOperation = entry.ledgerOperation();
        }
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.ledgerOperation.LedgerOperation;
import com.chargebee.v4.models.ledgerOperation.params.ListLedgerOperationsParams;
import com.chargebee.v4.models.ledgerOperation.responses.ListLedgerOperationsResponse;
import java.util.List;

public class ListLedgerOperations {

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

        ListLedgerOperationsParams params = ListLedgerOperationsParams.builder()
            .subscriptionId()
            .is("1mGETgZVF2umUZq")
            .sortBy()
            .created_at()
            .desc()
            .build();

        ListLedgerOperationsResponse response = client.ledgerOperations().listLedgerOperations(params);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.ledgerOperation.listLedgerOperations({
        subscription_id: {
            is: "1mGETgZVF2umUZq"
        },
        "sort_by[desc]": "created_at"
    });
    result.list.forEach((entry) => {
        console.log(entry);
        const ledgerOperation = entry.ledger_operation;
    });
} 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->ledgerOperation()->listLedgerOperations([
    "subscription_id" => [
        "is" => "1mGETgZVF2umUZq"
    ],
    "sort_by" => [
        "desc" => "created_at"
    ]
]);
foreach($result->list as $entry) {
    $ledgerOperation = $entry->ledger_operation;
}
```

#### Python

```python
from chargebee import Chargebee, Filters

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
entries = cb_client.LedgerOperation.list_ledger_operations(
    cb_client.LedgerOperation.ListLedgerOperationsParams(
        subscription_id=Filters.StringFilter(IS="1mGETgZVF2umUZq"),
        sort_by=Filters.SortFilter(DESC="created_at")
    )
)
for entry in entries.list:
    ledger_operation = entry.ledger_operation
```

#### Ruby

```ruby
require 'chargebee'

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

list = ChargeBee::LedgerOperation.list_ledger_operations({
  "subscription_id[is]" => "1mGETgZVF2umUZq",
  "sort_by[desc]" => "created_at"
})

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

## Sample Response

```json
{
  "list": [
    {
      "ledger_operation": {
        "id": "9lfj6x1f5",
        "subscription_id": "1mGETgZVF2umUZq",
        "unit_id": "ai_credits",
        "unit_type": "credit_unit",
        "type": "capture_authorization",
        "amount": "10",
        "provisioned_start_balance": "100.25",
        "provisioned_end_balance": "90.25",
        "overdraft_start_balance": "20",
        "overdraft_end_balance": "20",
        "ledger_operation_timestamp": 1774978580,
        "created_at": 1774978590,
        "modified_at": 1774978591,
        "object": "ledger_operation",
        "parent_ledger_operation_id": "eyexnp6sc"
      }
    },
    {..}
  ],
  "next_offset": "[\"1774978100000\",\"2019805959311302272\"]"
}
```

## URL Format

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

## Input Parameters

- `limit` (optional, integer, default=10, min=1, max=100)
  Specifies the maximum number of resources to return per page.
  
  **Default and Hard Cap**
  
  -   Optional parameter; if omitted, a server-defined default is applied.
  -   Values exceeding the server's maximum limit are capped (clamped) to the allowed maximum.
  
  **Example →** _limit = "50"_

- `offset` (optional, string, max chars=1000)
  Opaque cursor indicating the current position in the result set for pagination.
  
  **Behavior**
  
  -   To fetch the next page, pass the next\_offset value returned in the previous response.
  -   The value is opaque and must not be parsed, modified, or constructed manually.
  
  **Example →** _offset = "\["1771176208000","96000000006"\]"_

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

- `ledger_operation` (Ledger operation object)
  Resource object representing a ledger operation. The response is the standard Chargebee [list envelope](/docs/api/list-ops): `{ "list": [{ "ledger_operation": { ... } }, ...], "next_offset": "..." }`, where each `list` item wraps a single `ledger_operation` under its resource name.
