// Get the answer service
embed.on(EmbedEvent.Data, async (e) => {
const service = await embed.getAnswerService();
// Add columns to the answer
await service.addColumnsByName(["Sales", "Region"]);
// Get the data
const data = await service.fetchData();
console.log(data);
});
AnswerService
AnswerService provides a simple way to work with ThoughtSpot Answers.
This service allows you to interact with ThoughtSpot Answers programmatically, making it easy to customize visualizations, filter data, and extract insights directly from your application.
You can use this service to:
-
Add or remove columns from Answers (
addColumns
,removeColumns
,addColumnsByName
) -
Apply filters to Answers (
addFilter
) -
Get data from Answers in different formats (JSON, CSV, PNG) (
fetchData
,fetchCSVBlob
,fetchPNGBlob
) -
Get data for specific points in visualizations (
getUnderlyingDataForPoint
) -
Run custom queries (
executeQuery
) -
Add visualizations to Liveboards (
addDisplayedVizToLiveboard
)
Version : SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
// Get data for a point in a visualization
embed.on(EmbedEvent.CustomAction, async (e) => {
const underlying = await e.answerService.getUnderlyingDataForPoint([
'Product Name',
'Sales Amount'
]);
const data = await underlying.fetchData(0, 100);
console.log(data);
});
Indexπ
Constructorsπ
Should not need to be called directly.
new AnswerService(session: SessionInterface , answer: any , thoughtSpotHost: string , selectedPoints?: VizPoint[] ) : AnswerService
Should not need to be called directly.
Function Parameters
- session
-
-
session: SessionInterface
-
- answer
-
-
answer: any
-
- thoughtSpotHost
-
-
thoughtSpotHost: string
-
- selectedPoints
-
Optional
-
selectedPoints: VizPoint[]
-
Returns
Defined in : utils/graphql/answerService/answerService.ts
Methodsπ
addColumnsπ
addColumns(columnIds: string[] ) : Promise< any >
Add columnIds and return updated answer session.
Function Parameters
- columnIds
-
-
columnIds: string[]
-
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
addColumnsByNameπ
addColumnsByName(columnNames: string[] ) : Promise< any >
Add columns by names and return updated answer session.
Function Parameters
- columnNames
-
-
columnNames: string[]
-
Returns
Promise< any >
embed.on(EmbedEvent.Data, async (e) => {
const service = await embed.getAnswerService();
await service.addColumnsByName([
"col name 1",
"col name 2"
]);
console.log(await service.fetchData());
});
[definedInTag]#Defined in : link:https://github.com/thoughtspot/visual-embed-sdk/blob/main/src/utils/graphql/answerService/answerService.ts#L153[utils/graphql/answerService/answerService.ts, window=_blank]#
addDisplayedVizToLiveboardπ
addDisplayedVizToLiveboard(liveboardId: string ) : Promise< any >
Function Parameters
- liveboardId
-
-
liveboardId: string
-
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
addFilterπ
addFilter(columnName: string , operator: RuntimeFilterOp , values: string | number | bigint | boolean[] ) : Promise< any >
Add a filter to the answer.
Function Parameters
- columnName
-
-
columnName: string
-
- operator
-
-
operator: RuntimeFilterOp
-
- values
-
-
values: string | number | bigint | boolean[]
-
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
executeQueryπ
executeQuery(query: string , variables: any ) : Promise< any >
Execute a custom graphql query in the context of the answer.
Function Parameters
- query
-
-
query: string
-
graphql query
- variables
-
-
variables: any
-
graphql variables
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
fetchCSVBlobπ
fetchCSVBlob(userLocale?: string = 'en-us', includeInfo?: boolean = false) : Promise< Response >
Fetch the data for the answer as a CSV blob. This might be quicker for larger data.
Function Parameters
- userLocale
-
-
userLocale: string = 'en-us'
-
- includeInfo
-
-
includeInfo: boolean = false
-
Include the CSV header in the output
Returns
Promise< Response >
Defined in : utils/graphql/answerService/answerService.ts
fetchDataπ
fetchData(offset?: number = 0, size?: number = 1000) : Promise< {columns: any , data: any } >
Fetch data from the answer.
Function Parameters
- offset
-
-
offset: number = 0
-
- size
-
-
size: number = 1000
-
Returns
Promise< {columns: any , data: any } >
Defined in : utils/graphql/answerService/answerService.ts
fetchPNGBlobπ
fetchPNGBlob(userLocale?: string = 'en-us', omitBackground?: boolean = false, deviceScaleFactor?: number = 2) : Promise< Response >
Fetch the data for the answer as a PNG blob. This might be quicker for larger data.
Function Parameters
- userLocale
-
-
userLocale: string = 'en-us'
-
- omitBackground
-
-
omitBackground: boolean = false
-
Omit the background in the PNG
- deviceScaleFactor
-
-
deviceScaleFactor: number = 2
-
The scale factor for the PNG
Returns
Promise< Response >
Defined in : utils/graphql/answerService/answerService.ts
getAnswerπ
getAnswer() : Promise< any >
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
getFetchCSVBlobUrlπ
getFetchCSVBlobUrl(userLocale?: string = 'en-us', includeInfo?: boolean = false) : string
Just get the internal URL for this answerβs data as a CSV blob.
Function Parameters
- userLocale
-
-
userLocale: string = 'en-us'
-
- includeInfo
-
-
includeInfo: boolean = false
-
Returns
string
Defined in : utils/graphql/answerService/answerService.ts
getFetchPNGBlobUrlπ
getFetchPNGBlobUrl(userLocale?: string = 'en-us', omitBackground?: boolean = false, deviceScaleFactor?: number = 2) : string
Just get the internal URL for this answerβs data as a PNG blob.
Function Parameters
- userLocale
-
-
userLocale: string = 'en-us'
-
- omitBackground
-
-
omitBackground: boolean = false
-
- deviceScaleFactor
-
-
deviceScaleFactor: number = 2
-
Returns
string
Defined in : utils/graphql/answerService/answerService.ts
getSQLQueryπ
getSQLQuery() : Promise< string >
Returns
Promise< string >
Defined in : utils/graphql/answerService/answerService.ts
getSessionπ
getSession() : SessionInterface
Get the internal session details for the answer.
Returns
Defined in : utils/graphql/answerService/answerService.ts
getSourceDetailπ
getSourceDetail() : Promise< any >
Get the details about the source used in the answer. This can be used to get the list of all columns in the data source for example.
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
getTMLπ
getTML() : Promise< any >
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
getUnderlyingDataForPointπ
getUnderlyingDataForPoint(outputColumnNames: string[] , selectedPoints?: UnderlyingDataPoint[] ) : Promise< AnswerService >
Get underlying data given a point and the output column names. In case of a context menu action, the selectedPoints are automatically passed.
Function Parameters
- outputColumnNames
-
-
outputColumnNames: string[]
-
- selectedPoints
-
Optional
-
selectedPoints: UnderlyingDataPoint[]
-
Returns
Promise< AnswerService >
Version : SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
embed.on(EmbedEvent.CustomAction, e => {
const underlying = await e.answerService.getUnderlyingDataForPoint([
'col name 1' // The column should exist in the data source.
]);
const data = await underlying.fetchData(0, 100);
})
Defined in : utils/graphql/answerService/answerService.ts
removeColumnsπ
removeColumns(columnIds: string[] ) : Promise< any >
Remove columnIds and return updated answer session.
Function Parameters
- columnIds
-
-
columnIds: string[]
-
Returns
Promise< any >
Defined in : utils/graphql/answerService/answerService.ts
setTMLOverrideπ
setTMLOverride(override: any ) : void
Function Parameters
- override
-
-
override: any
-
Returns
void
Defined in : utils/graphql/answerService/answerService.ts