Skip to main content
curl --request POST \
  --url https://api.usedatabrain.com/api/v2/guest-token/create \
  --header 'Authorization: Bearer dbn_live_abc123...' \
  --header 'Content-Type: application/json' \
  --data '{
    "clientId": "user-456",
    "dataAppName": "sales-dashboard"
  }'
To obtain a guest token from DataBrain, utilize our REST API from your backend system. Each request will generate a unique guest token, ensuring security and flexibility. Once you acquire the guest token, you can seamlessly pass it to your frontend application, where it can be integrated with the web component.
Create API key from Databrain's dashboard that should be passed in the headers in these requests.
Guest tokens are designed for frontend embedding. Never expose your API key in frontend code — always generate tokens from your backend.

Quick start (simple use case):

When you need a guest token that you want to use across dashboards and metrics, all you have to do is pass clientId, dataAppName. If expiryTime is not passed, the token will not expire.

Cloud Databrain Endpoint:

POST https://api.usedatabrain.com/api/v2/guest-token/create

Self-hosted Databrain Endpoint:

POST <SELF_HOSTED_URL>/api/v2/guest-token/create
Generating GUEST TOKEN for your Dashboard/Metric Component.

Headers

NameTypeDescription
Authorization*StringBearer API TOKEN
Content-Type*StringMust be set to application/json for all requests

Request Body

NameTypeDescription
dataAppName*StringYour Data App Name
clientId*StringClient ID for whom this guest token is generated. ("clientId": "None" if no tenancy selected)
paramsObjectAdditional Params: allowedEmbeds, dashboardAppFilters, appFilters, hideDashboardFilters, userIdentifier, timezone
expiryTimeNumberIn milliseconds. Common values: 3600000 (1 hour), 86400000 (24 hours), 604800000 (7 days)
datasourceNameStringDatasource name from Data Studio (important in case of multi-datasource embed setup)
// 200: OK
{
  "token": "..."
}
// 400: Bad Request
{
  "error": {
    "message": "invalid dashboard id",
    "code": "<ERROR_CODE>"
  }
}
// 401: Unauthorized
{
  "error": {
    "message": "API key is invalid or expired",
    "code": "AUTHENTICATION_ERR"
  }
}

Request Body Examples:

Simple Request Body:

{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname"
}

Request Body with App Level Metric Filter:

App filter
A metric level filter designed specifically for controlling access to individual metrics. Unlike general RLS settings, it restricts access without requiring end user input or control.
{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "params": {
    "appFilters": [{
      "metricId": "The id of the metric you want to have app filters",
      "values": {
        "paid_orders": true,
        "amount": 500,
        "country": ["USA", "CANADA"] || "USA", // based on filter variant (select or multi)
        {
          "sql": "SELECT \"name\" FROM \"public\".\"countries\" WHERE isEnabled=true",
          "columnName": "name"
        }
      }
    }]
  }
}

Request.json

Dashboard App Filters:

Request Body with Dashboard filters:

{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "params": {
    "dashboardAppFilters": [
      {
        "dashboardId": "dashboard-id",
        "values": {
          // single string
          "name": "Eric",

          // multi select
          "country": ["USA", "CANADA"] || "USA", // based on filter variant (select or multi)
          {
            "sql": "SELECT \"name\" FROM \"public\".\"countries\" WHERE isEnabled=true",
            "columnName": "name"
          },

          // date-picker
          "timePeriod": { "startDate": "2024-01-01", "endDate": "2024-3-23" },

          // range
          "price": { "min": 1000, "max": 5000 }
        },
        "isShowOnUrl": true // true/false
      }
    ]
  }
}
In the above code snippet, "name", "country", "timePeriod", and "price" are Dashboard App filters.
When you disable the isShowOnUrl, the filter will not be visible to end users as search params on URL.

Datasource [Multi Datasource connection]:

{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "datasourceName": "data source name"
}
datasourceName is available in app data studio tab.

Hide Dashboard Filters:

To hide dashboard filters in an embedded dashboard:
{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "params": {
    "hideDashboardFilters": ["filter 1", "filter 2"] // name of dashboard filters to hide
  }
}

Allowed Embeds (optional)

To restrict where a guest token can be used, pass an allowlist of embed IDs in params.allowedEmbeds. When set, the token will only be able to load embedded dashboards whose dashboardId is included in that list.
{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "params": {
    "allowedEmbeds": ["embed_abc123", "embed_def456"]
  }
}

Dashboard Permissions

To enable or disable few dashboard permissions from backend:
{
  "clientId": "id", //"None" if no tenancy available
  "dataAppName": "dataappname",
  "permissions": {
    "isEnableArchiveMetrics": true, // true or false
    "isEnableManageMetrics": true, // true or false
    "isEnableCreateDashboardView": true, // true or false - allow creating custom dashboard views
    "isEnableMetricUpdation": true, // true or false
    "isEnableCustomizeLayout": true, // true or false
    "isEnableUnderlyingData": true, // true or false
    "isEnableDownloadMetrics": true, // true or false
    "isShowSideBar": true, // true or false - show the sidebar navigation
    "isShowDashboardName": true, // true or false - show the dashboard name in the interface
    "isDisableMetricCreation": false // true or false - disable metric creation for end users
  }
}

User Identifier for Private & Publish Metrics

Use userIdentifier inside the params object to uniquely identify the end-user in your embedded dashboard.
This enables features such as creating private metrics and publishing metrics directly from the embed view.
{
  "clientId": "id",
  "dataAppName": "dataappname",
  "params": {
    "userIdentifier": "unique-user-id-123"
  }
}

Note: userIdentifier should be a unique string representing the logged-in user in your system. When set, any metrics created by this identifier can be managed (private or published) within the embedded environment. isAllowPrivateMetricsByDefault should be enabled while creating the dashboard.

Timezone

Use timezone inside the params object to specify an IANA timezone string for timezone-aware queries and date/time formatting. When provided, SQL queries will be executed with this timezone setting, ensuring consistent date/time handling across different timezones. Supported Datasources: Clickhouse, Trino, Redshift, CockroachDB, Postgres, MSSQL Common timezone values: "UTC", "America/New_York", "America/Los_Angeles", "Europe/London", "Asia/Kolkata", "Australia/Sydney"
{
  "clientId": "id",
  "dataAppName": "dataappname",
  "params": {
    "timezone": "America/New_York"
  }
}

Code Examples

HTTP Status Codes

Status CodeDescription
200OK - Request succeeded
400Bad Request - Invalid request parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to resource
404Not Found - Resource not found
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Server error occurred
Rate Limiting: API requests are limited to prevent abuse. Implement exponential backoff for rate limited requests (429 status).

Error Codes:

Error CodeHTTP StatusDescription
AUTHENTICATION_ERROR401Invalid or missing API key
INVALID_REQUEST_BODY400Missing or invalid parameters
CLIENT_ID_ERROR400Invalid clientId format or value
DATA_APP_ID_ERROR404Data app not found
WORKSPACE_ID_ERROR404Workspace not found or inaccessible
DASHBOARD_PARAM_ERROR400Invalid dashboard filter parameters
APP_FILTER_PARAM_ERROR400Invalid app filter configuration
RLS_SETTINGS_PARAM_ERROR400Invalid RLS settings
RATE_LIMIT_EXCEEDED429Too many requests
INTERNAL_SERVER_ERROR500Server error
INVALID_PERMISSIONS403Invalid permission settings
EXPIRED_TOKEN401Token has expired