# Using the API

The Keypup [GraphQL](https://graphql.org/learn/) API allows you to perform all actions accessible via the user interface, which includes adding team members, creating insights & dashboards, querying our datasets, etc.

The Keypup API is split into two different purpose-specific endpoints:

- **The Platform API** (<https://hq.keypup.io/graphql>): This endpoint is the general-purpose API used to manage dashboards, insights, projects, and users.

- **The Reporting API** (<https://viz.keypup.io/graphql>): This endpoint is the actual reporting engine used by insights to query the datasets.

# 1 - Authentication

## 1.1 - Generating API tokens

You can generate an API token by going to [Settings > Account](https://hq.keypup.io/app/settings/user-account) and accessing the **API Token** tab. Note that this tab is only accessible if API access has been enabled on your account.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/2283071787/b88846ec0fe235ec1cd486bee716/keypup-api-tokens-create-token.png?expires=1796016600&amp;signature=d2992b71d4bd1c91f3ee092cda782f3c1bc786d237402276335f9f4a9d6c6e9a&amp;req=diIvFcl5nIZXXvMW1HO4zUZOHiw%2FUlzt9Q9n4CJjfj5%2BGPcqDXITla7CAMDc%0A94TRxR2mQlCmZbsuyaA%3D%0A)

Click on **Create token** to get started.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/2336444651/2baad1a438b620f948d896c1c2c1/api-create-token.png?expires=1796016600&amp;signature=4eb63542ca3714ddf0f0fd22dfb40aa3fea899b3cbc5cb7b58eecd5097845eb0&amp;req=diMkEM16mYdaWPMW1HO4zbLC8iMOO6fOfq7CI51%2B7CMMXmleB5wouKx71zXv%0AdgwYFja2%2B8HoNafnFqM%3D%0A)

We strongly recommend setting a descriptive name and **an expiration** for your token. Permanent tokens are available as well, but must be used with caution and **properly secured** on your side.

We also strongly recommend selecting the **minimum level of permissions** (scopes) for your token to reduce the overall risk/exposure.

Please note that the `companies:read` scope (or `hq:all:read`) is required to access company resources. Without it, only user-specific resources will be returned when applicable. See **Section 3** on available scopes for more details.

Once generated, tokens are available to be copied and pasted for 1 minute. After this delay, only a hint is provided.

**Are you going to support refreshable OAuth2 tokens?**
Yes. OAuth2 tokens are already supported for MCP Server accesses and will soon be made available for API tokens. Standard tokens will also remain available.

## 1.2 - Using API tokens for authentication

The Keypup API uses Bearer authentication via the `Authorization` header. Simply set the `Authorization` header as such:

| **Header**      | **Value**                  |
| --------------- | -------------------------- |
| `Authorization` | `Bearer <my_keypup_token>` |

The API authentication provides the same level of access as what you have on our user interface.

# 2 - Using the API

## 2.1 - Using the API Explorer

Our [API explorer](https://hq.keypup.io/flows/api-explorer) allows you to get started with both APIs. No tokens are required to use the Explorer since you are authenticated through your Keypup account.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/1325811751/417197acfc2fca5597431e2cde44/Screenshot%2B2025-01-08%2Bat%2B10_26_45.png?expires=1796016600&amp;signature=aa14fb8f5b97de428c307d18dc8df1146d064f4767f0c7194a777ee4159efcf8&amp;req=dSMlE8F%2FnIZaWPMW1HO4zavXlFUEb8G2sYrQFHJ4700Qg0QoHRSHhcMJNa1A%0ArBw7wql%2BaRoX525APPA%3D%0A)

You can **switch between APIs** using the top-left dropdown.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/1325749427/3665de75fd71d8931b1b0ef0bb6a/Screenshot+2025-01-08+at+10_28_41.png?expires=1796016600&amp;signature=f2ff2232dc50bf24d74f6189192288787988f543d6c83bfc154127fa74d7757b&amp;req=dSMlE856lIVdXvMW1HO4zZbtG193Uwp%2Fu7aSRylOWOdyK%2Bliy7hKVGgpYky%2F%0AKdvvOOlzDJHvQH9gJ10%3D%0A)

## 2.2 - Accessing the documentation of each API

GraphQL APIs are discoverable and self-documented. You can **access the documentation** of each API by clicking the book icon on the left side.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/1325752977/6cf45caf2686c5ec8510bf1807ce/Screenshot+2025-01-08+at+10_31_59.png?expires=1796016600&amp;signature=a0edb429131970ec9e00d7e60630c2ee7bb50fa03c6f4007d0aae5ebd84b5045&amp;req=dSMlE857n4hYXvMW1HO4zaHQLyYPYCw7O8gybcxQJo2DOUDavSMZPPArgRaR%0ABqy5%2BHW7MqN4YOw%2BIlA%3D%0A)

## 2.3 - Exporting insights as queries

Every insight runs one or more Reporting API queries. You can retrieve them from the insight editor, to explore them in the API Explorer, or from the API, to run them in your own scripts.

**From the insight editor**

After enabling API access on your account, a new "Open in API Explorer" button will appear in the Configure Table section of the insight editor.

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/2283073576/7ad1c799a908915901322da3e54e/keypup-chart-export-to-api.png?expires=1796016600&amp;signature=eb2c43ecf388d5037d7484e86eb8e1a17afce60ea49f07a541bf7d828b4c6fb2&amp;req=diIvFcl5noRYX%2FMW1HO4zQFy1k8Z4fjiax8aDInVgRa03Hw%2Bfd%2BoOlLGgVsr%0Ack%2Fj6vaxQmuitgYligs%3D%0A)

Clicking this button will open the query used by the insight in the [API Explorer](https://hq.keypup.io/flows/api-explorer).

![](https://downloads.intercomcdn.com/i/o/gb4j2pth/1325760370/314e4d99c2824fa5766503a1b1a5/Screenshot+2025-01-08+at+10_39_05.png?expires=1796016600&amp;signature=26e4a8517037587d9d826a8210ee98a80e242ff9b1f10ae6510cc71f06f3313d&amp;req=dSMlE854nYJYWfMW1HO4zWZceeMnmF6y35HtWEltGXDydbMHOopzJMzAR5rM%0AGt1nW24uKkvJQ7Husv4%3D%0A)

**From the API**

Every insight has a `queries` field on the Platform API. It returns the queries the insight runs, compiled from its configuration: its filters, metrics and dimensions, with "is me" rules and formula dimensions written out. Each query can be sent unchanged to the Reporting API's `report` query.

The field takes two optional arguments:

- `dashboardId`: applies that dashboard's dashboard-wide filters, so the queries return what the insight shows on that dashboard. The insight must be on the dashboard. When you read the insight through a dashboard's `widgets`, that dashboard is used by default.

- `asFormulas`: writes the metrics, dimensions and filters as formulas rather than functions with arguments, which is easier to read and edit. Defaults to `false`.

Below is an example retrieving the queries of an insight as it shows on a dashboard. In the API, an insight is a `widget`.

```
query($widgetId: ID, $dashboardId: ID) {
  widget(id: $widgetId) {
    name
    queries(dashboardId: $dashboardId, asFormulas: true) {
      target
      fact
      companyScopes
      metrics
      dimensions
      filters
      limit
      autoFillSeries
    }
  }
}
```

To retrieve the queries of every insight of a dashboard at once, read them through the dashboard:

```
query($dashboardId: ID) {
  dashboard(id: $dashboardId) {
    widgets {
      nodes {
        id
        name
        queries(asFormulas: true) { target fact companyScopes metrics dimensions filters limit autoFillSeries }
      }
    }
  }
}
```

Then pass the queries as they are to the Reporting API:

```
query($queries: [ReportQueryInput!]!) {
  report(queries: $queries) {
    results
    errors { message }
  }
}
```

- **One insight, several queries**: most insights run a single query, whose `target` is `main`. A KPI runs one for its value (`kpi-metric`) and one for its trend (`kpi-trend`). A decorator, such as a text block, runs none.

- **"Me" is the token's user**: an "is me" rule becomes the `ME()` operator, which the Reporting API resolves to the user the API token belongs to.

- **Invalid filters**: an insight whose filters are invalid returns an error explaining what is wrong, rather than queries.

Retrieving the queries needs the `hq:widgets:read` scope, and `hq:dashboards:read` to apply a dashboard's filters. Running them needs `viz:reports:read`.

**Using an AI assistant?** The [MCP server](https://docs.keypup.io/en/articles/15360547-using-the-mcp-server) returns the same queries for an insight or a whole dashboard, and runs them for you.

## 2.4 - Using queries in application code and scripts

GraphQL queries are POST requests composed of three components:

- The headers (see section "Using API tokens for authentication" above)

- The query, passed as a body text attribute

- The query variables, passed as a body JSON attribute

Below is an example of a cURL request making a query to our Platform API to get the name of a company, for which the ID is passed as a variable. The body is formatted as a JSON object with the `query` and `variables` attributes.

```
curl 'https://hq.keypup.io/graphql'
    -H 'Accept: application/json'
    -H 'Content-Type: application/json'
    -H 'Authorization: Bearer my_keypup_api_token'
    --data-raw '{"query":"query($companyId: ID) { company(id: $companyId) { name } }","variables":{"companyId":"a61bdee0-edbc-4888-9459-2ae3f2704f51"}}'
```

You can use any HTTP library in any language to make GraphQL queries. If manually building HTTP queries looks painful to you, you may consider one of the numerous open-source GraphQL clients out there.

A non-exhaustive list is available on the [GraphQL Tools & Libraries page](https://graphql.org/community/tools-and-libraries/?tags=client).

**Embedding queries in the browser**

It is not possible to embed queries in a web page via JavaScript. Our CORS policies prevent this for security reasons. Exposing your token in a web page would also be a bad idea.

If you wish to do so, then you should have an application server making backend queries to Keypup and serving HTML pages authenticated via cookie to your users.

# 3 - Available Scopes

Read and write scopes are available for each resource. They control the access that your API tokens have to the API and allow you to minimize risk exposure.

Some resources are specific to users, some specific to companies, and some to both.

If you intend to access company resources, your token must have the `companies:read` scope (or `hq:all:read`) on top of the resource-specific scope. Without the `companies:read` scope only resources belonging to the API token user will be returned.

Selecting a **Write** scope automatically grants the matching **Read** scope (you cannot have write without read).

Selecting `hq:all:read` or `hq:all:write` is a wildcard that covers every HQ entity, including any future entities added to the API.

## 3.1 Viz Scopes (Reporting API)

| **Entity** | **Scopes**         | **Description**                                                                                                              |
| ---------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| Reports    | `viz:reports:read` | Execute queries against the Viz reporting engine. Supports metrics, dimensions, filters, and pagination across all datasets. |

## **3.2 HQ Scopes (Platform API)**

| **Entity**             | **Scopes**                                                  | **Description**                                                                                                                                               |
| ---------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| All resources          | `hq:all:read`<br>`hq:all:write`                             | Wildcard scope granting access to all HQ platform resources, including any future resources added to the API.                                                 |
| Accounts               | `hq:accounts:read`                                          | Third-party organisations or workspaces discovered via integrations (e.g., a GitHub org, a Jira Cloud site). Relationship: Integration > Accounts > Projects. |
| API tokens             | `hq:api_tokens:read`                                        | Personal API tokens created by the user for programmatic access. Includes token metadata (description, expiration, scopes).                                   |
| Apps                   | `hq:apps:read`                                              | Integration app catalog (GitHub, GitLab, Jira, Bitbucket, Azure DevOps, etc.). Each app has a provider, category, and stage.                                  |
| Agent discussions      | `hq:agent_discussions:read`                                 | AI Agent conversation threads. Each discussion has a category (widget or dashboard) and contains a sequence of prompt/response parts.                         |
| Billing invoices       | `hq:billing_invoices:read`                                  | Stripe invoices associated with the company subscription (amount, status, dates).                                                                             |
| Billing subscriptions  | `hq:billing_subscriptions:read`                             | Company subscription plan and billing status managed via Stripe.                                                                                              |
| Companies              | `hq:companies:read`
​`hq:companies:write`                 | Team workspaces. Write access allows updating company name and AI steering configuration.                                                                     |
| Company invites        | `hq:company_invites:read`
​`hq:company_invites:write`     | Pending email invitations to join a team workspace (email, role, expiration).                                                                                 |
| Dashboards             | `hq:dashboards:read`
​`hq:dashboards:write`               | Dashboard resources including layout, filters, icon, description, and associated widgets.                                                                     |
| Identities             | `hq:identities:read`                                        | User identities across connected platforms - maps a user to their login username and provider (e.g., GitHub username, Jira account).                          |
| Import batches         | `hq:import_batches:read`                                    | Data import operations triggered when syncing projects. Tracks progress and status of each batch.                                                             |
| Integrations           | `hq:integrations:read`                                      | Active connections between an app (e.g., GitHub) and the company. Each integration has a status and links to an app provider.                                 |
| Pins                   | `hq:pins:read`
​`hq:pins:write`                           | Pinned dashboards and their assignment to pin groups in the sidebar navigation.                                                                               |
| Pin groups             | `hq:pin_groups:read`
​`hq:pin_groups:write`               | Named collections used to organize pinned dashboards in the sidebar (name, icon, ordering).                                                                   |
| Projects               | `hq:projects:read`                                          | Projects imported from connected integrations (repositories, Jira boards, Azure DevOps projects, etc.).                                                       |
| Roles                  | `hq:roles:read`
​`hq:roles:write`                         | Resource-level access control roles (owner, editor, viewer) assigned to users or the company on dashboards and widgets.                                       |
| Users                  | `hq:users:read`
​`hq:users:write`                         | User accounts (first name, email, profile). Write access allows updating user profile and unenrollment.                                                       |
| User company relations | `hq:user_company_rels:read`
​`hq:user_company_rels:write` | Memberships linking users to companies. Each membership has a role (admin, member), status, and optional expiration.                                          |
| User sessions          | `hq:user_sessions:read`                                     | Active authentication sessions for the current user (read-only).                                                                                              |
| Widgets                | `hq:widgets:read`
​`hq:widgets:write`                     | Individual insight widgets (charts, KPIs, tables, cards). Write access allows creating, updating, and deleting widgets.                                       |