This example demonstrates how to use the ThoughtSpot REST API SDK to call ThoughtSpot's v2 REST API in a React application.
import { createBearerAuthenticationConfig, ThoughtSpotRestApi } from "@thoughtspot/rest-api-sdk";
import { useEffect, useState } from "react";
const config = createBearerAuthenticationConfig(
"https://your-instance.thoughtspot.cloud",
async () => fetchTokenFromYourServer(),
);
const tsClient = new ThoughtSpotRestApi(config);
const LiveboardList = () => {
const [liveboards, setLiveboards] = useState([]);
useEffect(() => {
tsClient.searchLiveboards({}).then(setLiveboards);
}, []);
return (
<ul>
{liveboards.map((lb) => (
<li key={lb.id}>{lb.name}</li>
))}
</ul>
);
};Open in Codesandbox
- Links to the Thoughtspot developer docs for the features used in this example.
- Rest Api Reference
- Rest Api Sdk
. ├── api/ │ └── token-server.ts - A simple token server that returns a valid access token for the ThoughtSpot server └── src/ ├── App.tsx - The main React component that fetches liveboard lists from ThoughtSpot using the REST API SDK ├── thoughtspot-client/ │ └── thoughtspot-client.ts - A client for the ThoughtSpot REST API SDK └── get-auth-token.ts - A utility function for getting a valid access token for the ThoughtSpot
$ git clone https://github.com/thoughtspot/developer-examples
$ cd rest-api/typescript-sdk/react-rest-api
$ npm i
$ npm run dev
$ npm run start-token-server
- React
- Typescript
- Web