Vasu Pabbaraju - Hi , I am trying embed Thought...

Hi , I am trying embed ThoughtSpot into a Mobile Device (iOS). While I am trying to get an auth token I am getting following error "Failed to load auth token: [Error: Cannot reach ThoughtSpot server. Please check your network connection and ensure the app has been rebuilt.]" my guess is, something related CORS. Unfotunately I could not find any documentation on Mobile - CORS setting. Any help on this is greatly appreciated.
11 Replies
yuichirio_ha
yuichirio_ha2mo ago
Hey @Vasu Pabbaraju , Can I know what version of thoughtspot cl you are on. Also, I would like to check the code snippet for the same. And please do validate the token you will be using. And yes. please download the latest version through : https://github.com/thoughtspot/swift-embed-sdk I think you are using that anyways. Thanks.
GitHub
GitHub - thoughtspot/swift-embed-sdk
Contribute to thoughtspot/swift-embed-sdk development by creating an account on GitHub.
Vasu Pabbaraju
Vasu PabbarajuOP2mo ago
our code is based on Reac Native Here is the code snippet trying to call this to get auth token, in my react-native code const response = await fetch('https://<searver>.thoughtspot.cloud/api/rest/2.0/auth/token/full', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody), }); const requestBody = { "username": "<username>", "validity_time_in_sec": 300, "auto_create": false, "secretKey": "<secret>" }; "@thoughtspot/rest-api-sdk": "^2.4.1", "@thoughtspot/visual-embed-sdk": "^1.33.9",
Nicolas
Nicolas2mo ago
@yuichirio_ha the token was valid - it authenticate the user for a web session. However it failed for mobile specifically.
yuichirio_ha
yuichirio_ha2mo ago
Hey @Vasu Pabbaraju I meant thoughtspot server/cluster version. Also we are using react-native-embed sdk right ? https://www.npmjs.com/package/@thoughtspot/react-native-embed-sdk?activeTab=readme I got confused as you mentioned visual-embed-sdk. Also we have an example code for the react-native-embed-sdk : https://github.com/thoughtspot/developer-examples/tree/main/mobile/react-native-embed-sdk Please refer to this also if some setup or code related usage of the sdk. I tested with latest: react-native-embed-sdk with ios now. If none of the above resolves. You can add the findings. Or else we can connect tomorrow IST hours if possible. Thanks.
GitHub
developer-examples/mobile/react-native-embed-sdk at main · thought...
Example apps/solutions for Developers using ThoughtSpot - thoughtspot/developer-examples
Vasu Pabbaraju
Vasu PabbarajuOP2mo ago
I am using following "@thoughtspot/react-native-embed-sdk": "^0.0.2-beta", I have reviewed the sample code , issue I am facing is here , when I replaced "https://your-backend.com/api/get-ts-token'" with "https://<searver>.thoughtspot.cloud/api/rest/2.0/auth/token/full" network call is failing. getAuthToken: async () => { // Example: Fetch token from your backend // const response = await fetch('https://your-backend.com/api/get-ts-token'); // const data = await response.json(); // return data.token; return "YOUR_AUTH_TOKEN"; // Replace with actual token retrieval } am i calling wrong endpoint?
yuichirio_ha
yuichirio_ha2mo ago
Hey @Vasu Pabbaraju - So as you said it worked with your backend endpoint. So, it's not the issue with sdk. Now for the issue for getting token directly from the endpoint. Please check below function and you can use something similar. Also for your usage of direct api - use it something like this - I just tested it : With secret key. If you want to use direct endpoint we need these headers also.
export const getTokenDirectly = async (tokenConfig: any) => {
const { tsHost, username, password, secretKey } = tokenConfig;

const apiUrl = `${tsHost}/api/rest/2.0/auth/token/full`;

const requestBody: any = {
username: username,
validity_time_in_sec: 30000,
};

if (password && password !== '') {
requestBody.password = password;
} else if (secretKey && secretKey !== '') {
requestBody.secret_key = secretKey;
} else {
throw new Error('Either password or secret_key must be provided');
}

try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(requestBody),
});

const data = await response.json();

if (!response.ok) {
throw new Error(data.error?.message || `API Error: ${response.status}`);
}

return data.token;

} catch (error: any) {
throw error;
}
};
export const getTokenDirectly = async (tokenConfig: any) => {
const { tsHost, username, password, secretKey } = tokenConfig;

const apiUrl = `${tsHost}/api/rest/2.0/auth/token/full`;

const requestBody: any = {
username: username,
validity_time_in_sec: 30000,
};

if (password && password !== '') {
requestBody.password = password;
} else if (secretKey && secretKey !== '') {
requestBody.secret_key = secretKey;
} else {
throw new Error('Either password or secret_key must be provided');
}

try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify(requestBody),
});

const data = await response.json();

if (!response.ok) {
throw new Error(data.error?.message || `API Error: ${response.status}`);
}

return data.token;

} catch (error: any) {
throw error;
}
};
Nicolas
Nicolas5w ago
Hi @Vasu Pabbaraju , just wanted to follow up - did the above help resolve the issue you're facing?
Vasu Pabbaraju
Vasu PabbarajuOP2w ago
yes this issue is resolved
Vasu Pabbaraju
Vasu PabbarajuOP2w ago
@Nicolas @yuichirio_ha reallt appreciate your help on this Now, trying to resolve an MCP issue... here is the issue i am facing while testing MCP using developer-examples fast-mcp. 1. when I use "(Sample) Retail - Apparel" datasource, MCP getAnswer tool responds with some answer without failure. But when use 'frame_url' attribute to see the graph. I get "we could not complete your request" error 2. when I use our orgs datasource with MCP , i get following error Body: {"error":{"message":{"debug":{"debug":"No answer found for your query.","code":10004}}}} Any help on this is greatly appreciated.
No description
yuichirio_ha
yuichirio_ha2w ago
CC: @shikharTS can you PTAL. @Justin Mathew
shikharTS
shikharTS2w ago
Replied on the 2nd thread

Did you find this page helpful?