Data and Report APIs

Hi there, I need liveboard data after I change the filers. I am trying to fetch the liveboard data using REST API v2 (api/rest/2.0/metadata/liveboard/data). I call the API in onFilterChanged callback. The request is send on every filter change but I always receive the original data (no filters applied). In the docs you use createFormDataObjectWith to build the request body Could you please let me what this function should do? What body should I pass? In the same doscs you say to pass the transient_pinboard_content and than in the example you use transient_content. Which one is correct? This is the code I have:
import {
HostEvent,
LiveboardEmbed,
MessageCallback,
useEmbedRef,
} from '@thoughtspot/visual-embed-sdk/react';

const Liveboard = () => {
const embedRef = useEmbedRef<typeof LiveboardEmbed>();

const handleFilterChanged: MessageCallback = () => {
embedRef.current
.trigger(HostEvent.getExportRequestForCurrentPinboard)
.then(transientPinboardContent => {
fetch(
`${HOST}/api/rest/2.0/metadata/liveboard/data?metadata_identifier=${ID}`,
{
method: 'POST',
credentials: 'include',
body: JSON.stringify({
transient_content: transientPinboardContent,
}),
},
)
.then(response => response.json())
.then(console.log)
.catch(console.log);
});
};

return (
<LiveboardEmbed
ref={embedRef}
liveboardId={ID}
onFilterChanged={handleFilterChanged}
/>
);
};
import {
HostEvent,
LiveboardEmbed,
MessageCallback,
useEmbedRef,
} from '@thoughtspot/visual-embed-sdk/react';

const Liveboard = () => {
const embedRef = useEmbedRef<typeof LiveboardEmbed>();

const handleFilterChanged: MessageCallback = () => {
embedRef.current
.trigger(HostEvent.getExportRequestForCurrentPinboard)
.then(transientPinboardContent => {
fetch(
`${HOST}/api/rest/2.0/metadata/liveboard/data?metadata_identifier=${ID}`,
{
method: 'POST',
credentials: 'include',
body: JSON.stringify({
transient_content: transientPinboardContent,
}),
},
)
.then(response => response.json())
.then(console.log)
.catch(console.log);
});
};

return (
<LiveboardEmbed
ref={embedRef}
liveboardId={ID}
onFilterChanged={handleFilterChanged}
/>
);
};
Data and Report APIs
Data and Report APIs
9 Replies
Aditya
Aditya4mo ago
Hi @Adrian you will have to save the changes after changing the filter and then make the API call to get the updated data.
Adrian
AdrianOP4mo ago
I can see in the documentation that there is a way of fetching the data for unsaved liveboard. It says "To download or retrieve a Liveboard with unsaved changes...". Or maybe I don't understand that correctly?
Liveboard data API
The liveboard data API API allows you to query a pinboard and its visualizations
Aditya
Aditya4mo ago
I see. Let me check this internally and get back to you on this. cc: @shikharTS
shikharTS
shikharTS4mo ago
It looks like we have some bug around this, you should be able to download liveboard data with unsaved changes through API. Let me follow up internally and check this for you.
Adrian
AdrianOP4mo ago
Any update on this?
shikharTS
shikharTS4mo ago
Hey sorry, so there is some gap in the documentation here, here is a code which is working for me:
const embedRef = useEmbedRef<typeof LiveboardEmbed>();

const handleFilterChanged: MessageCallback = () => {
embedRef.current
.trigger(HostEvent.getExportRequestForCurrentPinboard)
.then((transientPinboardContent) => {
console.log(transientPinboardContent.data);

const payload = {
metadata_identifier: "abc",
data_format: "COMPACT",
record_offset: 0,
record_size: 10,
transient_content: JSON.stringify(transientPinboardContent.data),
};

fetch(
`https://{IP}/api/rest/2.0/metadata/liveboard/data`,
{
method: "POST",
headers: {
Authorization:
"Bearer xxx",
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
}
)
.then((response) => response.json())
.then(console.log)
.catch(console.log);
});
};

return (
<LiveboardEmbed
ref={embedRef}
liveboardId={"ID"}
fullHeight={true}
onFilterChanged={handleFilterChanged}
/>
);
const embedRef = useEmbedRef<typeof LiveboardEmbed>();

const handleFilterChanged: MessageCallback = () => {
embedRef.current
.trigger(HostEvent.getExportRequestForCurrentPinboard)
.then((transientPinboardContent) => {
console.log(transientPinboardContent.data);

const payload = {
metadata_identifier: "abc",
data_format: "COMPACT",
record_offset: 0,
record_size: 10,
transient_content: JSON.stringify(transientPinboardContent.data),
};

fetch(
`https://{IP}/api/rest/2.0/metadata/liveboard/data`,
{
method: "POST",
headers: {
Authorization:
"Bearer xxx",
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
}
)
.then((response) => response.json())
.then(console.log)
.catch(console.log);
});
};

return (
<LiveboardEmbed
ref={embedRef}
liveboardId={"ID"}
fullHeight={true}
onFilterChanged={handleFilterChanged}
/>
);
Can you check if this works for you
Adrian
AdrianOP4mo ago
It is working, thank you.
Adrian
AdrianOP4mo ago
It didn't because I was passing transient_content: JSON.stringify(transientPinboardContent) as a payload instead of transient_content: JSON.stringify(transientPinboardContent.data). The documentation for "Liveboard data with unsaved changes" is incorrect in 2 places. Now I know how it works but worth fixing the docs so you won't have to assist other users with that. Thanks a lot for your help!
Data and Report APIs
Data and Report APIs
shikharTS
shikharTS4mo ago
Yes I have raised an internal ticket to get it corrected. Thanks

Did you find this page helpful?