Hello, i need scripting using JS example. I want to getTable getSpace getView etc. Where can i access examples?
let mainTable = base.getTable(cursor.activeTableId);
something like this
Hi, are you looking for JavaScript SDK usage examples based on the API? If so, please check this help document with a JS SDK quick start guide: https://bika.ai/help/guide/developer/openapi
import { Bika } from 'bika.ai';
const bika = new Bika({
apiKey: '__PASTE_YOUR_API_TOKEN_FROM_USER_SETTING__',
baseURL: 'https://bika.ai/api/openapi/bika',
});
async function fetchData() {
try {
const spaces = await bika.spaces.list();
const space = spaces[0];
const nodes = await space.nodes.list();
const node = nodes[0];
const database = await node.asDatabase();
const records = await database.records.list();
console.log('Records:', records);
} catch (error) {
console.error('Error fetching data:', error);
}
}
fetchData();
If you need examples for using getTable, getSpace, and getView within Run Script Action, weâll add relevant tutorial documentation shortly. Stay tuned!
Got it. Have you seen our Run Script documentation at Run Script | Bika.ai ? It includes basic JS/Python examples showing how to return values.
The Run Script Action doesnât directly support getTable/getSpace/getView. Youâll need to combine actions to achieve this.
For example:
- Add a âFind Records action before âRun Scriptâ Action in your workflow to get database (run a test once to generate variables).
- In Run Script, use the âslash â/â key to open the variable picker and select the output from âFind Recordsâ action.
To get space lists:
Currently this requires calling our OpenAPI via fetch() in your script. See the API docs: https://bika.ai/help/openapi/bika#tag/Spaces/paths/~1v1~1spaces/get
(async () => {
const url = âhttps://bika.ai/api/openapi/bika/v1/spacesâ;
const apiKey = âTOKENâ; // Replace with your actual API key
const response = await fetch(url, {
method: âGETâ,
headers: {
âAuthorizationâ: Bearer ${apiKey}
,
âContent-Typeâ: âapplication/jsonâ
}
});
if (!response.ok) {
throw new Error(HTTP error! Status: ${response.status}
);
}
const data = await response.json();
console.log(data);
})();
i am not getting responses. Any idea?
Hey there! Looks like there are some syntax issues in your code causing it to fail. You might want to check out the code example below to fix it. Also, two quick tips:
- When using Run Script, make sure to return a value at the end - that becomes your actionâs output. Docs here: https://bika.ai/help/guide/automation/run-script-action
- console.log wonât show up in Automation Run History. For debugging, pack your variables into a JS object and return it to see the values. Hope this helps!
(async () => {
const url = 'https://bika.ai/api/openapi/bika/v1/spaces';
const apiKey = '{YOUR_API_TOKEN}';
const response = await fetch(url, {
'method': 'GET',
'headers': {
'Authorization': "Bearer " + apiKey,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error("HTTP error! Status:" + response.status);
}
return await response.json();
})();