> For the complete documentation index, see [llms.txt](https://help.enterprise.ledger.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.enterprise.ledger.com/api-documentation-v2/guides/balance-reporting-bot/2.-connect-to-revault-api.md).

# 2. Connect to revault-api

### Setup environment variables [​](broken://pages/VXxwkM8Dfw8U01UfR2Pu) <a href="#setup-environment-variables" id="setup-environment-variables"></a>

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:

{% tabs %}
{% tab title=".env" %}

<pre class="language-bash"><code class="lang-bash"><strong>REVAULT_API_URL="https://re.vault.ledger.com/v1/rest"
</strong>REVAULT_WORKSPACE="&#x3C;your-workspace>"
REVAULT_API_KEY_ID="&#x3C;your-api-key-id>"
REVAULT_API_KEY_SECRET="&#x3C;your-api-key-secret>"
</code></pre>

{% endtab %}
{% endtabs %}

### Login to API ​ <a href="#login-to-api" id="login-to-api"></a>

#### Edit the script file ​ <a href="#edit-the-script-file" id="edit-the-script-file"></a>

Update the `main.ts` file content:

{% tabs %}
{% tab title="main.ts" %}

```bash
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();
```

{% endtab %}
{% endtabs %}

#### Test the script ​ <a href="#test-the-script" id="test-the-script"></a>

Run the command again:

```bash
npm run dev
```

It should output:

```
> vault-bot@1.0.0 dev /tmp/vault-bot
> tsx main.ts

Successfully logged as BobAPI
```

{% hint style="warning" %}
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.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.enterprise.ledger.com/api-documentation-v2/guides/balance-reporting-bot/2.-connect-to-revault-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
