Developers

Get started with the API

Tutorial5 min readContent reviewed
Markdown ↓
On this page

This tutorial builds a server-side read flow: find a vault, resolve its asset and chain, then load its current and historical snapshots. First run the example against a synthetic offline fixture, then repeat it with an issued integration key. The live steps use documented routes and response shapes; they were not executed with production credentials for this tutorial.

Run the offline example#

Download vault-read.mjs and vault-read.fixture.json into the same directory. With Node.js 24 or later, run:

bash
node vault-read.mjs --fixture

This mode reads only the sibling JSON file and makes no network requests. Every address, identifier, network, amount, and observation in the fixture is synthetic. Expected output:

json
{
  "mode": "fixture (synthetic, offline)",
  "vault": {
    "id": "000000000000000000000001",
    "name": "Synthetic tutorial vault",
    "address": "0x1111111111111111111111111111111111111111"
  },
  "network": {
    "name": "Synthetic fixture network",
    "chainID": 31337
  },
  "asset": {
    "symbol": "SYN",
    "decimals": 6
  },
  "latest": {
    "block": 1000000,
    "timestamp": "2023-11-14T22:13:20.000Z",
    "underlyingTVL": "25.000000"
  },
  "history": {
    "returned": 2,
    "totalCount": 3,
    "nextOffset": 2
  }
}

The example checks the fields it consumes, keeps raw amounts as strings, converts token units using BigInt, and distinguishes an empty snapshot from a zero balance. It reads only the first history page and reports the next offset; it is a small read example, not a complete polling service.

1. Configure a server-side key#

bash
export PARETO_API_KEY='issued-key'
export PARETO_API_URL='https://api.pareto.credit'

Use the key only from trusted server infrastructure.

Run the same script against the documented API origin:

bash
node vault-read.mjs

It selects the first accessible vault with both tokenId and chainId from a ten-item catalog page. To select a particular accessible vault, use the returned database ID:

bash
node vault-read.mjs --vault-id "$VAULT_ID"

Set VAULT_ID from a real response as shown below. No fixture ID should be used as a live ID. The script fixes its live origin to https://api.pareto.credit, sends a bearer key, rejects redirects, and uses a 15-second request timeout. It reports non-success HTTP status codes without printing credentials. See API errors for production retry and rate-limit handling.

2. Discover a vault#

Request a small, ordered catalog page. The result's data items provide a vault _id, tokenId, and chainId.

bash
curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/vaults?limit=10&sort=name&order=asc"

Choose a vault from data and copy its _id into VAULT_ID. If data is empty, confirm your catalog access with your integration contact before continuing.

The list envelope is { "data": [...], "totalCount": 1 }; each selected item needs _id, tokenId, and chainId for this flow. Those fields are database IDs. The vault's address is a separate on-chain identity. The fixture demonstrates this selected response shape:

json
{
  "data": [{
    "_id": "000000000000000000000001",
    "name": "Synthetic tutorial vault",
    "tokenId": "000000000000000000000002",
    "chainId": "000000000000000000000003"
  }],
  "totalCount": 1
}

These are illustrative selected fields, not a production observation or a complete resource schema. The generated vault reference defines the published request and response contract.

bash
export VAULT_ID='paste-the-returned-vault-id'

3. Resolve the vault, token, and chain#

Diagram
API resources for one vault. Selected conceptual API response map, not a complete physical database schema. Use the resource _id values for API joins, numeric chainID for network selection, addresses for on-chain identities and token decimals for raw token quantities. Latest blocks are materialized vault-block observations. Vault performances are persisted records; /v1/vaults/performances is a separate aggregate calculation, not another entity in this map. Types, categories, operators, campaigns and token-price observations are omitted.API resources for one vault. Selected conceptual API response map, not a complete physical database schema. Use the resource _id values for API joins, numeric chainID for network selection, addresses for on-chain identities and token decimals for raw token quantities. Latest blocks are materialized vault-block observations. Vault performances are persisted records; /v1/vaults/performances is a separate aggregate calculation, not another entity in this map. Types, categories, operators, campaigns and token-price observations are omitted.
Selected conceptual API response map, not a complete physical database schema. Use the resource _id values for API joins, numeric chainID for network selection, addresses for on-chain identities and token decimals for raw token quantities. Latest blocks are materialized vault-block observations. Vault performances are persisted records; /v1/vaults/performances is a separate aggregate calculation, not another entity in this map. Types, categories, operators, campaigns and token-price observations are omitted. Open full diagram and source scope.
bash
curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/vaults/$VAULT_ID"

The detail response is the vault object itself, without a data wrapper. Copy its tokenId and chainId, then retrieve those records:

bash
export TOKEN_ID='paste-the-returned-token-id'
export CHAIN_ID='paste-the-returned-chain-id'

curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/tokens/$TOKEN_ID"

curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/chains/$CHAIN_ID"

A token's decimals is required before presenting or calculating its raw token amounts. Chain chainID identifies the blockchain network; it differs from the database CHAIN_ID. Some vaults have no underlying token configured; choose a vault with tokenId and chainId for this tutorial.

4. Load the current snapshot and history#

Use the latest-block endpoint for the current materialized vault state, then request historical blocks in time order.

bash
curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/vault-latest-blocks?vaultId=$VAULT_ID&limit=1"

curl --fail-with-body -H "Authorization: Bearer $PARETO_API_KEY" \
  "$PARETO_API_URL/v1/vault-blocks?vaultId=$VAULT_ID&sort=timestamp&order=asc&limit=50"

Both responses use { "data": [...], "totalCount": ... }. The latest snapshot is data[0]; an empty array means no matching snapshot is available. Inspect its block.number and block.timestamp to label the observation. For the next history page, repeat the request with offset=50; continue according to the pagination rules.

For comparison, the executable example uses limit=2&offset=0 on history so the fixture demonstrates a next offset. Vault, token, and chain detail reads return resource objects directly, whereas latest/history reads return page envelopes. A snapshot's selected fields look like this synthetic example:

json
{
  "data": [{
    "vaultId": "000000000000000000000001",
    "block": { "number": 1000000, "timestamp": 1700000000 },
    "TVL": { "token": "25000000", "USD": "0" }
  }],
  "totalCount": 1
}

The example formats only TVL.token with underlying decimals. It does not calculate USD values, share prices, fees, or aggregate performance; those fields have their own data conventions. A latest indexed snapshot can lag the chain.

You now have the vault's metadata, underlying asset precision, network, latest indexed state, and first history page. See data conventions before converting raw amounts or using a rate in an end-user calculation.

Next tasks#