ThoughtSpot Cloud: 9.6.0.cl
ThoughtSpot Software: 9.8.0.sw
TypeScript SDK
The REST API SDK library for TypeScript is available on the NPM site.
Supported versionsπ
Note the version recommendations for your ThoughtSpot clusters:
SDK version | Minimum required version on ThoughtSpot cluster |
---|---|
v2.0.2 | |
v2.1.0 | ThoughtSpot Cloud: 9.7.0.cl |
v2.2.0 | ThoughtSpot Cloud: 9.8.0.cl |
v2.4.0 | ThoughtSpot Cloud: 9.10.0.cl |
v2.4.1 | ThoughtSpot Cloud: 9.10.5.cl |
v2.5.0 | ThoughtSpot Cloud: 9.12.0.cl, 9.12.5.cl |
v2.6.0 | ThoughtSpot Cloud: 10.1.0.cl |
v2.7.1 | ThoughtSpot Cloud: 10.1.0.cl |
For information about new features, breaking changes, and deprecated parameters, see API changelog.
Get startedπ
Before you begin, check the following:
-
Node.js version 18 or later is installed.
-
Access to a ThoughtSpot instance. Make sure you have the following information:
-
User credentials
-
URL of the ThoughtSpot instance
-
Secret key (Required for trusted authentication only)
-
-
User privileges and object permissions to view, edit, or create ThoughtSpot objects and resources.
Setup and usageπ
Complete the following steps:
-
Install the SDK in your local directory.
npm install @thoughtspot/rest-api-sdk --save
-
Import the SDK.
import { createBearerAuthenticationConfig, ThoughtSpotRestApi, } from '@thoughtspot/rest-api-sdk';
-
Create a client session using one of the following options:
-
Get an authentication token via
getAuthToken
method.const config = createBearerAuthenticationConfig("CLUSTER_SERVER_URL", getAuthToken); const tsRestApiClient = new ThoughtSpotRestApi(config); const getAuthToken = async () => { returns "BEARER TOKEN"; }
-
To obtain a token on behalf of another user, use
secret_key
instead ofpassword
. The secret key is generated on ThoughtSpot if Trusted authentication is enabled on your ThoughtSpot instance. For more information, see Secret key management.const config = createBearerAuthenticationConfig("CLUSTER_SERVER_URL", { username: "USERNAME", secret_key: "SECRET_KEY", }); const tsRestApiClient = new ThoughtSpotRestApi(config);
If the user account doesnβt exist in ThoughtSpot, you can provision a user just in time and assign privileges.
const config = createBearerAuthenticationConfig(); const tsRestApiClient = new ThoughtSpotRestApi(config); tsRestApiClient.getFullAccessToken( // GetFullAccessTokenRequest { username: "USERNAME", secret_key: "SECRET_KEY", email: "[email protected]", display_name: "display_name_example", auto_create: true, org_id: 0, group_identifiers: [ "GROUP-A", "GROUP-B", ], } ).then((data: any) => { console.log('API called successfully. Returned data: ' + data); }).catch((error: any) => console.error(error));
-
Use basic authentication with
username
andpassword
:const config = createBearerAuthenticationConfig("CLUSTER_SERVER_URL", { username: "YOUR_USERNAME", password: "PASSWORD", }); const tsRestApiClient = new ThoughtSpotRestApi(config); };
-
If a session cookie is already set via either Visual Embed SDK or login method, you can send requests without authentication.
const config = createConfiguration({ baseServer: new ServerConfiguration("CLUSTER_SERVER_URL", {}), }); const tsRestApiClient = new ThoughtSpotRestApi(config);
-
-
Send a test request.
-
Try creating a user as shown in the following example. To view and copy the supported parameters and values, use the REST API v2 Playground.
import { createBearerAuthenticationConfig, ThoughtSpotRestApi, } from '@thoughtspot/rest-api-sdk'; const tsRestApiClient = new ThoughtSpotRestApi(config); tsRestApiClient.createUser( // CreateUserRequest { name: "UserA", display_name: "User A", password: "123Guest!", email: "[email protected]", account_type: "LOCAL_USER", account_status: "ACTIVE", visibility: "SHARABLE", notify_on_share: true, show_onboarding_experience: true, onboarding_experience_completed: false, preferred_locale: "en-CA", trigger_welcome_email: true, } ).then((data: any) => { console.log('API called successfully. Returned data: ' + data); }).catch((error: any) => console.error(error));
-
Try a GET call, for example, get a list of users via
searchUsers
. To get specific details, you can specify optional parameters such asvisibility
,account_type
,account_status
,group_identifiers
, and so on. To get the details of a user, specify the name or GUID of the user asuser_identifier
.import { createBearerAuthenticationConfig, ThoughtSpotRestApi, } from '@thoughtspot/rest-api-sdk'; const tsRestApiClient = new ThoughtSpotRestApi(config); tsRestApiClient.searchUsers( // SearchUsersRequest (optional parameters) { user_identifier: "UserA", } ).then((data: any) => { console.log('API called successfully. Returned data: ' + data); }).catch((error: any) => console.error(error));
-
Error handlingπ
The SDK raises errors when the HTTP response code indicates an error. You can use these error codes to handle or log errors as shown in the following example:
const test = async () => {
const client = getClientWithoutAuth(HOST);
try {
const data = await client.searchUsers({});
const names = data.reduce((names, user) => {
return names + " " + user.name;
}, "");
console.log(names);
} catch (e) {
switch (e.code) {
case 401: {
alert("Unauthorized error");
break;
}
case 400: {
alert("Incorrect input");
break;
}
default: {
alert("Server error " + e.code);
}
}
}
};
SDK Referenceπ
For a complete list of methods to use for API requests, see the following resources:
Category | Methods | HTTP Endpoints |
---|---|---|
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|