https://grainql.com/dashboard
covers one-time questions and live monitoring without code. This page is the task guide. The
field tables, error tables, and limits are on the reference pages, starting with
Query API.
Before you start, make sure that you have:
- A tenant on the Builder plan or higher. The Free plan has no Query API.
- The tenant alias from the dashboard. It is not the tenant UUID.
- An HTTP client. Analytics Web has no Query API methods.
Get an API key
- Open
https://grainql.com/dashboard/settings, then Authentication. - Click Generate New Secret.
- Enter a name, for example
Query API key. - Select the Query API permission.
- Copy the secret. The dashboard shows it one time.
- Store the secret in an environment variable named
GRAIN_API_KEY.
authStrategy. It works when the SDK uses NONE,
SERVER_SIDE, or JWT. Read Authentication.
Your first query
Every request sends the key in theX-API-Key header. This request reads ten page views from
January 2024:
properties holds what track sent. userId holds what
identify or setUserId set. Read Query events for
the field table and the paging rules.
To select events, add a filterSet. This request reads the events of one user:
properties.<name>, nested paths such as properties.user.plan,
eventName, userId, and eventTs. Read Filters for
the ten operators.
Count events
When you need a number and not the events, call the count endpoint. It takes the same body withoutpagination:
List event names
To find out which event names the tenant holds, call the list endpoint:Common tasks
Export a date range
Page through the query endpoint withsize 1000, then write the events to a file. This Node.js
script exports January 2024:
A dashboard of totals
Send one count per number, in parallel, then divide on the client:A funnel check
Count each step of the funnel with the same date range, then compare the numbers:Limits
The rate limit applies per API key, and the plan sets it.
Custom plans with higher limits exist.
Rules for the rate limit:
- Count the requests of a task before you run it. One page and one count are one request each.
- Queue requests in one place. Do not let several parts of an application call the API at the same time.
- If the API returns
429, waitRetry-Afterseconds, then retry one time. - Cache a number that a dashboard shows often.
Keep the key on the server
- Store the key in an environment variable, and add the
.envfile to.gitignore. - When a browser needs data, call the Query API from your own backend route, and return the result to the browser.
- To rotate a key, create a new key in the dashboard, deploy the application with the new key, then make sure that the application works, then revoke the old key.