T-Invest Node SDK Node.js
On this page

List accounts

Listing accounts verifies your connection to the T-Invest API and gives you an account ID for your next call.

Set up the connection

The TInvestNodeSDK constructor takes a token and an endpoint for the chosen environment. For the production API, a token with read access to the relevant accounts is enough. Get a T-Bank token

Environment gRPC endpoint
Production API invest-public-api.tbank.ru:443
Sandbox sandbox-invest-public-api.tbank.ru:443

Create the SDK, get an account, and close the channel

Pass the token and endpoint from your application's configuration to listAccounts. It calls sdk.sandbox.getSandboxAccounts() for the sandbox and sdk.users.getAccounts() for the production API.

getting-started.ts
import { TInvestNodeSDK } from '@woodger/t-invest-node-sdk';

export async function listAccounts(token: string, endpoint: string) {
  const sdk = new TInvestNodeSDK({ token, endpoint });

  try {
    const { accounts } = endpoint === 'sandbox-invest-public-api.tbank.ru:443'
      ? await sdk.sandbox.getSandboxAccounts({})
      : await sdk.users.getAccounts({});
    return accounts;
  }
  finally {
    sdk.close();
  }
}

Check the result

Each item in accounts has an id, a name, and a status. Pass the selected account's id as accountId in the next request.

An empty array means the token has access to no accounts in the chosen environment. In the sandbox, you can create a test account and repeat the request. Sandbox example

Close the SDK after the request

sdk.close() in finally closes the shared gRPC channel after a response or an error.

The next examples cover deadlines, response metadata, and related calls. Unary calls · Errors and lifecycle