"metadata": [
{
"identifier": "my_model",
"type": "LOGICAL_TABLE"
}
]
Data APIs
ThoughtSpot provides the following REST API v2 endpoints to fetch data:
-
POST /api/rest/2.0/searchdatato search data from a given data source. -
POST /api/rest/2.0/metadata/liveboard/datato get data from a Liveboard. -
POST /api/rest/2.0/metadata/answer/datato get data from a saved Answer.
If Role-Based Access Control (RBAC) is enabled, the DATADOWNLOADING (Can download Data) privilege is required to use these APIs. Alternatively, if the granular data download RBAC privileges are enabled for your ThoughtSpot instance, the CAN_DOWNLOAD_DETAILED_DATA (Can download detailed data) is required.
|
Note
| To download a Liveboard or Answer as a PDF, PNG, CSV, or XLSX file instead of retrieving its data as JSON, see Report APIs. |
Search data APIπ
The /api/rest/2.0/searchdata endpoint requires you to specify the data source object ID and a query string for a successful API call. You can also define additional parameters such as runtime_filter, runtime_sort, and runtime_param_override to apply runtime overrides on the data set.
Data sourceπ
To search data via API call, you require at least view access to the data source object. The data source object can be a Model, View, or Table.
You can specify the data source object GUID in the logical_table_identifier. The search data endpoint doesnβt support searching data from multiple Models, Views, or Tables in a single API request.
To find the GUID of the Model, View, or Table, use one of the following methods:
- Get data object GUID via API
-
Send an API request to the
/api/rest/2.0/metadata/searchendpoint with the following parameters in the metadata array:ExampleIf you donβt know the exact name of the data source object, specify the metadata
typeasLOGICAL_TABLEin your API request, and then copy the GUID of the data object from the API response. - Find the GUID of the data object via UI
-
-
Log in to your ThoughtSpot application instance:
-
Navigate to Data workspace.
https://<your-thoughtspot-instance>/#/data/tables/
-
On the Data workspace > Data objects page, select the data object. For example, if the data source object is a Model, click Models and then open the Model.
-
In the address bar of the web browser, note the GUID of the data source object. For example, in the following address string, the GUID is
9d93a6b8-ca3a-4146-a1a1-e908b71b963f:https://<your-thoughtspot-instance>/#/data/tables/9d93a6b8-ca3a-4146-a1a1-e908b71b963f
-
Copy the GUID.
-
Search queryπ
When issuing a query through the ThoughtSpot UI, users make selections to disambiguate a query. It is often difficult to programmatically use the result set of a query that runs in the ThoughtSpot UI search bar. Because the selection is not possible with an API approach, the API query language is modified to include query disambiguation.
Components of a search queryπ
In ThoughtSpot Query Language, the components of a query are classified into various types of tokens:
- Column
-
Columns must be enclosed in square brackets, [ ].
For example, in the query revenue by ship mode, both revenue and ship mode are columns. A valid query for the API is:
[revenue] by [ship mode]
- Operator
-
ThoughtSpot supports various operators such as =, !=, >, >=, <=, <, contains, not contains, and so on. Use these operators in the API query in the same manner as in the UI.
For example, specify revenue over 1000, and limit ship mode to 'air':
[revenue] > 1000 [ship mode] = 'air'
- Value
-
String (text) and date values must be enclosed within quotes, ''. Do not use quotes for numeric values, except for dates.
When using multiple values, separate them by a comma.
For example, when a ThoughtSpot UI query is revenue top 2 ship mode, the equivalent API query is:
[revenue] top 2 [ship mode]
For example, when a ThoughtSpot UI query is revenue ship mode = air, the equivalent API query is:
[revenue] [ship mode] = 'air'
- Date Bucket
-
In the ThoughtSpot UI, when there are several date columns, users can bind date bucket tokens to a specific column. When using the API, this binding between the date column and the date bucket must be made explicit. Use a period to separate the column with which the date bucket is bound, and the date bucket token.
Single word date buckets can be expressed as is. Multi-word date buckets must be enclosed within quotes.
For example, when a ThoughtSpot UI query is
revenue commit date monthly, and if monthly is bound to commit date, the equivalent API query is:[revenue] [commit date].monthly
When a ThoughtSpot UI query is
revenue day of week = 5, and if day of week is bound to commit date, the equivalent API query is as follows:[revenue] [commit date].'day of week' = 5
- Keyword
-
Use keywords in the API query in the same manner as in the UI.
For example, when a ThoughtSpot UI query uses keywords growth of and sort by, the equivalent API query is as follows:
growth of [revenue] by [commit date]
- Calendar
-
You can specify a custom calendar in the query. Use the calendar.calendar_name format explicitly.
When the calendar name contains multiple words, enclose these words in single quotes.
For example, when a ThoughtSpot UI query is revenue by commit date fiscal, where the name of the calendar is fiscal, the equivalent API query is as follows:
[revenue] by [commit date] calendar.fiscal
For example, when a ThoughtSpot UI query is revenue by commit date my calendar, where the name of the calendar is my calendar, the equivalent API query is:
[revenue] by [commit date] calendar.'my calendar'