# GraphQL API

## Overview

The graphQL API enables users to query information on vaults, transactions, and accounts over periods of time. It also enables users to build complex queries across schemas and run those queries in a single call.&#x20;

## How it works

### Building Queries

At the core of our graphQL API are the queries. Each query has a specific name and returns a specific data set, just like a REST endpoint.&#x20;

For example, `getPoolFlexAccountForDateRange` returns a daily snapshot of an account for a flexible term vault over a specified period of time, while `getPoolEvents` returns a list of events for a given vault (e.g. deposits, withdrawals, interest accruals) etc. &#x20;

But graphQL queries enables you to do a few things that REST cannot. Those are primarily

1. **You can combine multiple queries in a single call.** For example, you could combine `getPoolFlexAccountForDatRange` and `getPoolEvents` into a single query and it will return a daily snapshot of the specified account for a given vault *and* a list of all events for that vault.
2. **You can be very specific about which information you want returned.** For example, the `getPoolFlexAccountForDateRange` can return over 20 different fields, but you can build the query to return only the fields you care about (e.g. current balance and interest accrued).&#x20;
3. **You can query data over a specified period of time, the latest data, and summary data.** For example, you can use `getPoolFlexAccountForDateRange` query to return the closing balance on an account and interest accrued for the past 30 days, you could use `getPoolFlexAccount` to get the balance and interest accrued right now, or you could use `getPoolFlexAccountSummaryForDateRange`  to return the total amount of interest accrued over the past 30 days.&#x20;

When you combine all three of these capabilities, the graphQL API provides a very powerful, flexible, yet simple way to build queries for building UIs, reports, ledgers, reconciliations, and much more.&#x20;

### Variables

Each graphQL query requires one or more variables to be specified in the query and returns data based on the variables provided. There are four variables:

1. <mark style="color:yellow;">poolAddr</mark> - the contract address of the vault being queried
2. <mark style="color:yellow;">accountAddr</mark> - the wallet address of the account being queried
3. <mark style="color:yellow;">startDayStr</mark> - the beginning of the time period for which data will be returned
4. <mark style="color:yellow;">endDayStr</mark> - the end of the time period for which data will be returned

Not all queries require all variables. Each query will specify which variables are required.&#x20;

## graphQL URLs

Each environment and network has a unique URL&#x20;

<table><thead><tr><th width="197">Environment</th><th width="200">Network</th><th>URL</th></tr></thead><tbody><tr><td>Production</td><td>Ethereum</td><td><a href="https://gql.open-trade.io">https://gql.open-trade.io</a></td></tr><tr><td>Production</td><td>Avalanche</td><td><a href="https://avalanchegql.open-trade.io">https://avalanchegql.open-trade.io</a></td></tr><tr><td>Sandbox</td><td>Ethereum (Sepolia)</td><td><a href="https://gql.opentradesandbox.com">https://gql.opentradesandbox.com</a></td></tr></tbody></table>

## Postman

The best way to view detailed documentation and test the graphQL API is via our Postman workspace. To gain access, simply provide your email address to your account manager and you will receive an invitation to join the workspace.&#x20;

For a tour of Postman and guide on how to use it, we've provided the video below. &#x20;

{% embed url="<https://www.youtube.com/watch?v=MvVm3p5sjuo>" %}
