JavaScript SDK
The labii-sdk package provides browser-oriented resource methods for the Labii API.
The current SDK reads the API data center, authenticated user, and selected company from Labii browser storage. The examples assume that this Labii application context is already available.
Install
npm install labii-sdk
Quick start
Import the default Labii object.
import Labii from "labii-sdk";
Call a resource method. This callback example lists rows in a table.
Labii.Row.list({
serializer: "list",
query: "table__sid={{table_sid}}",
callback_success: (response) => {
console.log(response.data.results);
},
callback_fail: (error) => {
console.error(error);
},
});
The SDK uses the pattern Labii.Resource.method(props). For example, Labii.Column.list(...) lists columns and Labii.Workspace.modify(...) updates a workspace.
See the API reference for the resource name, supported operation, and required query string for each endpoint.
Request styles
Callbacks
Without is_async: true, requests use callback_success and callback_fail.
Labii.Workspace.retrieve({
sid: "{{workspace_sid}}",
callback_success: (response) => {
console.log(response.data);
},
callback_fail: (error) => {
console.error(error);
},
});
Async and await
Set is_async: true to receive the Axios response as the returned Promise value.
const response = await Labii.Workspace.retrieve({
sid: "{{workspace_sid}}",
is_async: true,
});
console.log(response.data);
A method does not return its API response in callback mode.
Standard methods
list
Labii.Row.list({
page: 1,
page_size: 10,
all_pages: false,
level: "organization",
sid: "{{organization_sid}}",
serializer: "list",
query: "table__sid={{table_sid}}&is_archived=false",
callback_success: (response) => {
console.log(response.data.results);
},
});
List properties:
level: List scope. The default isorganization.sid: SID for the selected level. The default is the selected company SID from browser storage.serializer: Response representation. The default islist.query: Query string without a leading?.pageandpage_size: Pagination settings.all_pages: Follow pagination and combine the results whentrue.callback_successandcallback_fail: Callback handlers.is_async: Return the Axios response whentrue.
create
Pass the request body in data.
Labii.Row.create({
data: {
name: "Sample 1",
workspaces: [{sid: "{{workspace_sid}}"}],
},
query: "table__sid={{table_sid}}",
callback_success: (response) => {
console.log(response.data);
},
});
create also accepts level, sid, query, callback handlers, and is_async. The SDK sends create requests with the detail serializer.
retrieve
Pass the resource SID.
Labii.Row.retrieve({
sid: "{{row_sid}}",
callback_success: (response) => {
console.log(response.data);
},
});
modify
Pass the resource SID and update body.
Labii.Workspace.modify({
sid: "{{workspace_sid}}",
data: {name: "Updated research workspace"},
callback_success: (response) => {
console.log(response.data);
},
});
delete
Pass the resource SID.
Labii.WorkspacePermission.delete({
sid: "{{workspace_permission_sid}}",
callback_success: () => {
console.log("Deleted");
},
});
delete is present only on resources configured for deletion. See the API reference before using it.
Common properties
retrieve, modify, and delete accept sid and an optional query. modify also requires data. All methods accept:
callback_successcallback_failis_asyncurl, for a documented custom endpoint that does not use the standard resource URL
Create rows in bulk
Labii.Row.bulk_create sends at most 50 rows in one request. Unlike the Python SDK, the JavaScript SDK does not split larger inputs into multiple requests.
Labii.Row.bulk_create({
sid: "{{organization_sid}}",
query: "table__sid={{table_sid}}",
data: {
rows: [
{name: "Sample 1", workspaces: [{sid: "{{workspace_sid}}"}]},
{name: "Sample 2", workspaces: [{sid: "{{workspace_sid}}"}]},
],
},
callback_success: (response) => {
response.data.results.forEach((result) => {
if (result.error) {
console.error(
"Row " + (result.index + 1) + " failed: " + result.error
);
}
});
},
});
Properties:
data: An object with arowsarray.query: Required and must includetable__sid.level: The default isorganization.sid: The default is the selected company SID from browser storage.- Callback handlers or
is_async: true.
Each result contains the input index and either sid and name or an error.
Resource names
Resource names come from the SDK's resource registry and are case-sensitive. Examples used by the API reference include:
ApikeyOrganization,Personnel,Team,Organizationwidget,Backup,CertificationWorkspace,WorkspacePermission,ApplicationTable,Column,Row,Cell,Section,Sectioncomment,Filter,Version,Activity,Visitor,Signer,PermissionNotification,Widget,Workflow,Executionlog,Dashboard,Auditevent
For example, the JavaScript API-key resource is Labii.Apikey, while the Python resource is labii.APIKey.