Ledger Enterprise
API Documentation V2
API Documentation V2
  • Introduction
    • Getting Started
    • Overview
  • Guides
    • Authentication
    • Balance Reporting Bot
      • 1. Project setup
      • 2. Connect to revault-api
      • 3. Fetch accounts balances
      • 4. Conclusion
  • reference
    • API reference
      • Users
      • Accounts
        • Transactions
      • Groups
      • Whitelists
      • Policies
      • Entities
      • Requests
        • Generate registration challenge
        • Confirm registration challenge
        • Challenge
        • Approve
        • Reject
      • Auth
        • Token
          • Refresh
      • Permissions
        • Allowed actions
        • Resources
      • Assets
        • Currencies
        • Tokens
      • Tradelink
        • Network
          • Blueprint
    • Specification
Powered by GitBook
On this page
  • Setup environment variables ​
  • Login to API ​
  1. Guides
  2. Balance Reporting Bot

2. Connect to revault-api

This part will cover how to setup API HTTP client and authenticate as API user.

Setup environment variables ​

Create a .env file with this content, replacing <your-api-key> and <your-api-secret> with your user's credentials and <your-workspace> by your target workspace:

REVAULT_API_URL="https://re.vault.ledger.com/v1/rest"
REVAULT_WORKSPACE="<your-workspace>"
REVAULT_API_KEY_ID="<your-api-key-id>"
REVAULT_API_KEY_SECRET="<your-api-key-secret>"

Login to API ​

Edit the script file ​

Update the main.ts file content:

import "dotenv/config";
import axios from "axios";

async function main() {
  const client = axios.create({
    baseURL: process.env.REVAULT_API_URL,
  });

  // authenticate & retrieve `accessToken` from user's credentials
  const authResponse = await client.post("/auth/token", {
    workspace: process.env.REVAULT_WORKSPACE,
    apiKeyId: process.env.REVAULT_API_KEY_ID,
    apiKeySecret: process.env.REVAULT_API_KEY_SECRET,
  });
  const accessToken = authResponse.data.accessToken as string;

  // add the Authorization header to every request
  client.interceptors.request.use((config) => {
    config.headers.Authorization = `Bearer ${accessToken}`;
    return config;
  });

  // fetch the current authenticated user
  const userResponse = await client.get("/users/me");
  const user = userResponse.data as { name: string };

  console.log(`Successfully logged as ${user.name}`);
}

// launch the script
main();

Test the script ​

Run the command again:

npm run dev

It should output:

> [email protected] dev /tmp/vault-bot
> tsx main.ts

Successfully logged as BobAPI

If you don't see the successful message, please verify that you followed all the steps precisely and that your credentials are valid.

If the problem persists, please contact support.

Previous1. Project setupNext3. Fetch accounts balances

Last updated 28 days ago