# Read a customer ledger

Operation / SDK: `readLedger` · `read_ledger` · `ReadLedger`

Read a page of the Customer ledger with its business references.

Last updated: 2026-11-06

[Web version](https://www.longplayai.com/docs/api/read-ledger)

<a id="request"></a>

## Request

- **Credential**: Server Key (with `customerId`) or Customer Token, scope `credits:read`.
- **SDK**: JavaScript `createLongplayServer().readLedger` · JavaScript `createLongplay().readLedger` · Python `read_ledger` · Go `ReadLedger`
- **Success**: HTTP 200

The response shows example data.

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/customer-ledger" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "query": {
    "type": null,
    "from": null,
    "to": null,
    "after": null,
    "limit": 50
  },
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}'
```

**TypeScript: readLedger.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function readLedger() {
  return longplay.readLedger({
    query: {
      type: null,
      from: null,
      to: null,
      after: null,
      limit: 50,
    },
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
  });
}
```

**Request body: request.json**

```json
{
  "query": {
    "type": null,
    "from": null,
    "to": null,
    "after": null,
    "limit": 50
  },
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}
```

**Response: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "ledger": {
    "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d",
    "rows": [
      {
        "id": "943d12d9-ac64-41f2-816e-aa9a70aaf4e5",
        "occurredAt": "2026-10-03T12:00:00.000Z",
        "type": "invoice",
        "status": "1Example",
        "paid": "1",
        "refunded": "1",
        "currency": "USD",
        "externalId": "1Example"
      }
    ],
    "nextCursor": null
  }
}
```

<a id="parameters"></a>

## Body parameters

**application/json**

- `customerId` (uuid, optional): The Customer's UUID.
- `query` (object, required): Query.
- `query.type` (enum | null, required): Return only entries of this type; `null` returns every type.
- `query.resourceKey` (string, optional): Resource identifier returned by balances: a Feature key for independent allowances, or pool:<poolId> for pools. minLength: 1 · pattern: ^[a-zA-Z0-9_-]+$
- `query.kind` (enum, optional): Kind; see the allowed values. Values: `"purchase"`, `"refund"`.
- `query.topup` (boolean, optional): When `true`, return only invoices that include a top-up Product; `false` or omitted applies no filter.
- `query.from` (date | null, required): Range start (ISO 8601).
- `query.to` (date | null, required): Range end (ISO 8601).
- `query.after` (object | null, required): Pagination cursor: pass the value from the previous page; `null` for the first page.
- `query.after.at` (date-time, required): Cursor field: occurrence time (ISO 8601) of the last row on the previous page. Pass the previous `nextCursor` unchanged.
- `query.after.id` (uuid, required): Cursor field: ID of the last row on the previous page (the entry `id` in a ledger, the `operationId` in a credit statement). Pass the previous `nextCursor` unchanged.
- `query.after.type` (enum, required): Cursor field: entry type of the last row on the previous page. Pass the previous `nextCursor` unchanged. Values: `"source"`, `"usage"`, `"transaction"`, `"invoice"`, `"debt"`, `"settlement"`.
- `query.limit` (integer, required): Maximum records per page, subject to the contract limit. min: 1 · max: 50

<a id="response"></a>

## Response fields

Every successful response includes `requestId` (this request's ID, for support) and `scope` (App and environment).

**HTTP 200 · application/json**

- `requestId` (uuid, required): UUID the server generated for this HTTP request; include it when reporting a problem. It is not your business requestId.
- `scope` (object, required): The App and environment of this response. Headers only verify scope; they cannot switch key scope.
- `scope.projectId` (string, required): App ID bound to the credential. minLength: 1
- `scope.environment` (enum, required): Separate data scope: sandbox or live. Values: `"sandbox"`, `"live"`.
- `ledger` (object, required): A page of the Customer's financial ledger entries, newest first, with `nextCursor` for the next page.
- `ledger.customerId` (uuid, required): The Customer's UUID.
- `ledger.rows` (array, required): Data rows. maxItems: 50
- `ledger.rows.id` (uuid | uuid | uuid | uuid | uuid | uuid, required): UUID of the record in this row: the balance grant (use it as `grantId`), the ledger entry (unique together with `type`) or the invoice (use it as `invoiceId`).
- `ledger.rows.occurredAt` (date-time | date-time | date-time | date-time | date-time | date-time, required): Timestamp (ISO 8601).
- `ledger.rows.type` ("invoice" | "source" | "usage" | "transaction" | "debt" | "settlement", required): Entry type: `source` a balance grant; `usage` a balance operation; `transaction` a verified payment or refund; `invoice` a verified invoice; `debt` an amount owed on a balance source; `settlement` a payment, usage refund or payment return applied to a debt.
- `ledger.rows.status` (string | enum, optional): Status; see the allowed values.
- `ledger.rows.paid` (string, optional): Amount paid on the invoice, in major units of `currency` (for example `12.5`); decimal string. pattern: ^(0|[1-9]\d{0,17})(\.\d{1,12})?$
- `ledger.rows.refunded` (string, optional): Refunded portion. pattern: ^(0|[1-9]\d{0,17})(\.\d{1,12})?$
- `ledger.rows.currency` (enum | enum | null, optional): Currency code supported by the published price.
- `ledger.rows.externalId` (string | null, optional): external ID.
- `ledger.rows.internal_feature_id` (uuid | uuid | uuid | uuid, optional): Feature ID.
- `ledger.rows.key` (string | string | string, optional): Key of the Feature this entry belongs to.
- `ledger.rows.name` (string | string | string | string, optional): Display name; not a unique identifier.
- `ledger.rows.kind` (enum | enum | enum | enum | enum, optional): Kind; see the allowed values.
- `ledger.rows.reason` (enum | enum | null, optional): Rejection reason or ledger operation description; interpret with accepted and status.
- `ledger.rows.quantity` (string | string, optional): Quantity as a decimal string, avoiding floating-point error.
- `ledger.rows.unlimited` (boolean, optional): Whether it is unlimited.
- `ledger.rows.startsAt` (date-time, optional): Timestamp (ISO 8601).
- `ledger.rows.expiresAt` (date-time | null | date-time | null, optional): Expiry time (ISO 8601, UTC).
- `ledger.rows.orderId` (uuid | null | uuid, optional): order ID.
- `ledger.rows.parentSourceId` (uuid | null, optional): For a source carried over from an earlier source (rollover), the ID of that earlier source; otherwise `null`.
- `ledger.rows.originalId` (uuid | null | uuid | null, optional): original record ID.
- `ledger.rows.accepted` (boolean, optional): Whether business rules accepted the operation. HTTP 200 does not imply accepted is true.
- `ledger.rows.properties` (object, optional): Validated pricing properties used to match dimensions and multipliers.
- `ledger.rows.reservationStatus` (enum | null, optional): Reservation status; see the allowed values.
- `ledger.rows.charges` (array, optional): How an accepted usage operation was funded: balance sources charged (`balance`), quantity not drawn from any balance (`unbilled`), and prepaid or postpaid charges. Empty for rejected operations, set-usage entries and zero-quantity consumption. maxItems: 500
- `ledger.rows.charges.funding` ("balance" | "unbilled" | "prepaid" | "postpaid", required): Funding source; see the allowed values.
- `ledger.rows.charges.sourceId` (uuid, optional): balance source ID.
- `ledger.rows.charges.rolloverId` (uuid | null, optional): rollover ID.
- `ledger.rows.charges.units` (string | string | string, optional): Part of the usage quantity covered by this charge, in units of the usage entry's Feature; decimal string.
- `ledger.rows.charges.amount` (string | string, optional): Credit or ledger amount, using the field’s decimal-string or integer type.
- `ledger.rows.charges.internal_feature_id` (uuid, optional): Feature ID.
- `ledger.rows.charges.key` (string, optional): Key of the Feature charged by this `prepaid` charge; present only on `prepaid` charges. minLength: 1 · pattern: ^[a-zA-Z0-9_-]+$
- `ledger.rows.charges.name` (string, optional): Display name; not a unique identifier. minLength: 1 · maxLength: 120
- `ledger.rows.charges.kind` (enum, optional): Kind; see the allowed values. Values: `"access"`, `"metered"`, `"credit"`.
- `ledger.rows.charges.invoiceId` (uuid, optional): invoice ID.
- `ledger.rows.charges.invoiceLineId` (uuid, optional): invoice line ID.
- `ledger.rows.charges.authorizationId` (uuid, optional): authorization ID.
- `ledger.rows.charges.currency` (enum, optional): Currency code supported by the published price. Values: `"USD"`, `"EUR"`, `"CNY"`, `"GBP"`, `"JPY"`, `"CAD"`, `"AUD"`, `"NZD"`, `"CHF"`, `"HKD"`, `"SGD"`, `"KRW"`, `"INR"`, `"BRL"`, `"MXN"`, `"TWD"`, `"THB"`, `"IDR"`, `"MYR"`, `"PHP"`, `"VND"`, `"ZAR"`, `"AED"`, `"SAR"`, `"SEK"`, `"NOK"`, `"DKK"`, `"PLN"`, `"CZK"`, `"HUF"`, `"ILS"`, `"TRY"`, `"RON"`.
- `ledger.rows.purpose` (enum, optional): What the payment was for: `product` a Product Version purchase; `invoice` payment of an invoice. Values: `"product"`, `"invoice"`.
- `ledger.rows.productVersionId` (uuid | null, optional): Product Version ID.
- `ledger.rows.productName` (string | null, optional): Product name.
- `ledger.rows.productVersion` (integer | null, optional): Version number of the purchased Product Version; `null` when `purpose` is `invoice`.
- `ledger.rows.invoiceId` (uuid | null, optional): invoice ID.
- `ledger.rows.amountMinor` (integer | null, optional): Amount in the currency's minor unit, such as cents.
- `ledger.rows.sourceId` (uuid | uuid, optional): balance source ID.
- `ledger.rows.transactionId` (uuid, optional): Ledger transaction UUID from the original consumption, referenced by a refund.
- `ledger.rows.amount` (string | string, optional): Credit or ledger amount, using the field’s decimal-string or integer type.
- `ledger.rows.debtId` (uuid, optional): ID of the `debt` entry this settlement applies to.
- `ledger.nextCursor` (object | null, required): Next-page cursor; null means end. Pass unchanged and clear when filters change.
- `ledger.nextCursor.at` (date-time, required): Occurrence time (ISO 8601) of the last row on this page; part of the cursor to pass unchanged as `after`.
- `ledger.nextCursor.id` (uuid, required): ID of the last row on this page. Pass the whole `nextCursor` object back unchanged to read the next page.
- `ledger.nextCursor.type` (enum, required): Entry type of the last row on this page; part of the cursor to pass unchanged as `after`. Values: `"source"`, `"usage"`, `"transaction"`, `"invoice"`, `"debt"`, `"settlement"`.

<a id="errors"></a>

## Errors

Failures return an error object; handle them by `error.code` and `error.recovery`. The table lists the errors that follow from this operation's credential, scope and idempotency fields; depending on the request it can also return `NOT_FOUND` (a referenced resource doesn't exist), `NOT_CONFIGURED` (a required integration isn't connected) or `PAYLOAD_TOO_LARGE`. Some refusals, such as insufficient balance, are not errors but a `reason` in a successful response.

**Possible errors**

| code | HTTP | When | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | The request doesn't match this page's parameters. A missing or malformed protocol header returns `UNSUPPORTED_PROTOCOL_VERSION` or `INVALID_PROTOCOL_VERSION` instead. | `fix_request` |
| `UNAUTHENTICATED` | 401 | The credential is missing, invalid, expired or revoked. | `authenticate` |
| `FORBIDDEN` | 403 | The credential lacks `credits:read`. | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` or `X-Indiana-Environment` doesn't match the credential's App and environment. | `check_scope` |
| `RATE_LIMITED` | 429 | Too many requests; wait for `Retry-After` and retry the same request. | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | The service is temporarily unavailable; retry the same request. | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | The outcome is unknown; retry later. | `recover_operation` |

- [Error codes and recovery](https://www.longplayai.com/docs/api/errors.md)
- [Request conventions](https://www.longplayai.com/docs/api.md)
- [All operations](https://www.longplayai.com/docs/api/operations.md#credits)
