Sorting

REST API endpoints that return paginated responses may provide a possibility to sort the results by one of the result properties. Not all properties can be used for sorting. Please check the endpoint documentation to find out the sorting properties.

Requests

In addition to the endpoint-specific parameters, endpoints that return sorted results accept the following parameters to control the sorting property and the order:

ParameterTypeDescription

order_by

string

Sorting property the results should be sorted by

order_direction

string

Order direction: ASC or DESC

The defaults are different for different endpoints and are provided in the corresponding endpoint documentation.

Example

Get blocks sorted by height from lowest to highest:

curl -X 'GET' \
  'https://api.testnet.cspr.cloud/blocks?order_by=block_height&order_direction=ASC' \
  -H 'accept: application/json' \
  -H 'authorization: 55f79117-fc4d-4d60-9956-65423f39a06a'
{
  "data": [
    {
      "block_height": 0,
      "block_hash": "975ea4de188c2a67946188cea0ec8a93d2d38286d7642526d50c45839a291210",
      "parent_block_hash": "0000000000000000000000000000000000000000000000000000000000000000",
      "state_root_hash": "e88b7c061760134ba37ad312c1e2d6373121748e9c61bcea19cc57510829addf",
      "era_id": 0,
      "proposer_public_key": "0106ca7c39cd272dbf21a86eeb3b36b7c26e2e9b94af64292419f7862936bca2ca",
      "native_transfers_number": 0,
      "contract_calls_number": 0,
      "is_switch_block": false,
      "timestamp": "2021-04-08T17:00:57Z"
    },
    {
      "block_height": 1,
      "block_hash": "f8ebb3a81c9c70faeaec896c94e7e56c75a5e1548e1b8dfe639c1b31610e5d22",
      "parent_block_hash": "975ea4de188c2a67946188cea0ec8a93d2d38286d7642526d50c45839a291210",
      "state_root_hash": "e88b7c061760134ba37ad312c1e2d6373121748e9c61bcea19cc57510829addf",
      "era_id": 0,
      "proposer_public_key": "017d96b9a63abcb61c870a4f55187a0a7ac24096bdb5fc585c12a686a4d892009e",
      "native_transfers_number": 0,
      "contract_calls_number": 0,
      "is_switch_block": false,
      "timestamp": "2021-04-08T17:02:02Z"
    },
    ...
    {
      "block_height": 9,
      "block_hash": "590f7b20a276ef7a2a2fba6871ad781a56fad16daa0ee80b4f214f7870652255",
      "parent_block_hash": "2e601c65dbfde43948eef998b8ab5c68d9f95b35612eb0245444903ea419c185",
      "state_root_hash": "f6985aa0d6dc760fd651f5d86bb3ecb7b9d3b56860b437aa83a0fa489dab9d3b",
      "era_id": 0,
      "proposer_public_key": "017d96b9a63abcb61c870a4f55187a0a7ac24096bdb5fc585c12a686a4d892009e",
      "native_transfers_number": 0,
      "contract_calls_number": 3,
      "is_switch_block": false,
      "timestamp": "2021-04-08T17:10:47Z"
    }
  ],
  "item_count": 2291305,
  "page_count": 229131
}

Last updated