# ledger_index

[[Source]](https://github.com/XRPLF/clio/blob/develop/src/rpc/handlers/LedgerIndex.cpp)

The `ledger_index` command looks up information about the last closed ledger at a given real-world time. This may be useful for correlating events that happened off-chain with historical data in the XRP Ledger. New in: Clio v2.3.0

This method is only available from the Clio server, not `rippled`.

## Request Format

An example of the request format:

WebSocket

```json
{
    "id": "example_ledger_index",
    "command": "ledger_index",
    "date": "2024-08-28T22:59:00Z"
}
```

JSON-RPC

```json
{
    "method": "ledger_index",
    "params": [
        {
            "date": "2024-08-28T22:59:00Z"
        }
    ]
}
```

The request can contain the following parameters:

| `Field` | Type | Required? | Description |
|  --- | --- | --- | --- |
| `date` | String | No | An ISO 8601 timestamp of the time to look up. Must be formatted without microseconds, and using `Z` as the time zone marker. For example, `2024-08-28T22:59:00Z`. If omitted, use the current time. |


## Response Format

An example of a successful response:

WebSocket

```json
{
  "result": {
    "ledger_index": 3679660,
    "ledger_hash": "346C9211428A102081A3BFFCCBE1F698E7E56163BBD1DF81B446418B3213DBD7",
    "closed": "2024-08-28T23:00:00Z",
    "validated": true
  },
  "id": "example_ledger_index",
  "status": "success",
  "type": "response",
  "warnings": [
    {
      "id": 2001,
      "message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
    }
    ]
}
```

JSON-RPC

```json
200 OK

{
  "result": {
    "ledger_index": 3679660,
    "ledger_hash": "346C9211428A102081A3BFFCCBE1F698E7E56163BBD1DF81B446418B3213DBD7",
    "closed": "2024-08-28T23:00:00Z",
    "validated": true,
    "status": "success"
  },
  "warnings": [
    {
      "id": 2001,
      "message": "This is a clio server. clio only serves validated data. If you want to talk to rippled, include 'ledger_index':'current' in your request"
    }
  ]
}
```

The response follows the [standard format](/docs/references/http-websocket-apis/api-conventions/response-formatting), with a successful result containing information about the most recently closed ledger at the requested time, including the following fields:

| Field | Type | Description |
|  --- | --- | --- |
| `ledger_index` | Number | The [Ledger Index](/docs/references/protocol/data-types/basic-data-types#ledger-index) of the most recently closed ledger at the specified time. |
| `ledger_hash` | String | The identifying [Hash](/docs/references/protocol/data-types/basic-data-types#hashes) of the most recently closed ledger at the specified time. |
| `closed` | String | The official close time of the most recently closed ledger at the specified time. |
| `validated` | Boolean | If `true`, the ledger has been validated by the consensus process and is immutable. Otherwise, the contents of the ledger are not final and may change. |


Note
Due to the rounding on ledger close times, there may be a difference of up to 10 seconds between the "official" close time of a ledger and the real-world clock time when the ledger was closed. For more details, see [Ledger Close Times](/docs/concepts/ledgers/ledger-close-times).

## Possible Errors

* Any of the [universal error types](/docs/references/http-websocket-apis/api-conventions/error-formatting#universal-errors).
* `invalidParams` - One or more fields are specified incorrectly, or one or more required fields are missing.
  * For example, this can occur if the specified `date` included a microseconds component.
* `lgrNotFound` - The server does not have ledger history for the specified point in time.