3. Fetch accounts balances
Now let's focus in listing all accounts in the workspace to retrieve their balances.
Types definition
Export Account & Paginated types
Let's start by adding an Account type, that define some properties listed in Account response, and a a generic type Paginated<T> for paginated responses (see Page-based pagination).
For convenience, let's create a separated types.ts file where we'll define the types definition for the responses:
Import types in the main script
From our main.ts file, let's import the newly created types:
import "dotenv/config";
import axios from "axios";
import { Account, Paginated } from "./types";
async function main() {
...Fetch accounts
Call the /accounts endpoint
/accounts endpoint Update the main.ts script again to add a call to /accounts:
Run the script
It should list the first page of accounts:
Loop in all pages
Adapt the script to pagination
There is a little problem in our script: it only fetches the first page of results (maximum of 30 items by page).
Let's update our script so it will loop until there is no more next page:
main.ts
ts
Verify that it works
It should looks in all pages (you might not see any difference if you have less than 30 accounts):
Last updated