🙏Get a guest token

This page will help you to get a guest token which you can use to access the dashboard metrics in your app using the databrain plugin.

Step 1: Go to the Databrain app settings and then click on the API Token tab.

Step 2: Find the API Key which has permission to access metrics and dashboards

Step 3: Open your Postman App and send a POST request to the URL - https://api.usedatabrain.com/api/v1/guest-token/create

Step 4: Then click on the Authorization tab and select the type to Bearer Token and paste the API Key you have copied from the Databrain App settings API Token tab.

Step 5: In the body tab choose raw json. We need a client id which you have to get from your user's session because ideally, you will call this API from your app only.

Step 6: The minimum json body structure should be -

 {
        "workspaceName": "your workspace name",
	“clientId”: “Your client or user Id for which you are creating this guest token”,	
}

If you want to add some Row Level of Security settings then in params you can also add another key “rlsSettings” It is an array of objects which has “metricId” - the id of the metric you want to have rls settings enabled for along with the key “values” which is an object of rls condition name and its value pair filter for the particular metric.

Now our new json body structure would be -

{
	"workspaceName": "your workspace name",
	“clientId”: “Your client or user Id for which you are creating this guest token”,
	“params: {
		“rlsSettings”: [{
			“metricId”: “The id of the metric you want to have rls filters”,
			“values”: {
				“paid_orders”: true,
				“amount”: 500
			}
		}]
	}
}

If you use SQL query to generate the metric data and want to add metric filters but don't want end users to use them then you can add appFilters

Please refer to this article to know more about app filters.

App filter

To add app filters it's the same process as rls settings. Here you have to add another key "appFilters" and then you can specify the value same as rls settings.

{
	"workspaceName": "your workspace name",
	“clientId”: “Your client or user Id for which you are creating this guest token”,
	“params: {
	...(other params),
		“appFilters”: [{
			“metricId”: “The id of the metric you want to have app filters”,
			“values”: {
				“paid_orders”: true,
				“amount”: 500,
				“country”: ["USA", "CANADA"]
			}
		}]
	}
}

Step 7: Click on the send button and in the response you will get the token. Now copy the token to use it in the plugin.

Last updated