A strongly-typed TypeScript SDK for interacting with the ThingsBoard REST API.
npm install thingsboard-sdk
The SDK is organized into domain-specific clients, each handling a specific area of the ThingsBoard API. Here's how to use them:
import {
UserControllerClient,
DeviceControllerClient,
DashboardControllerClient
} from 'thingsboard-sdk';
// Initialize clients for different API domains
const userClient = new UserControllerClient('http://localhost:8080');
const deviceClient = new DeviceControllerClient('http://localhost:8080');
const dashboardClient = new DashboardControllerClient('http://localhost:8080');
// Set authentication token (after login)
userClient.setAuthToken('YOUR_JWT_TOKEN');
deviceClient.setAuthToken('YOUR_JWT_TOKEN');
dashboardClient.setAuthToken('YOUR_JWT_TOKEN');
// Example: Login
const loginResult = await userClient.loginPost({
username: 'admin@thingsboard.org',
password: 'admin'
});
// Example: Get devices
const devices = await deviceClient.getTenantDevicesUsingGET({
pageSize: 10,
page: 0
});
// Example: Get dashboards
const dashboards = await dashboardClient.getTenantDashboardsUsingGET({
pageSize: 10,
page: 0
});
The SDK provides the following client classes, each corresponding to a specific API domain:
AdminControllerClient - System administration operationsAlarmControllerClient - Alarm managementAssetControllerClient - Asset managementAuthControllerClient - Authentication and authorizationCustomerControllerClient - Customer managementDashboardControllerClient - Dashboard operationsDeviceControllerClient - Device managementEntityGroupControllerClient - Entity group operationsTenantControllerClient - Tenant managementUserControllerClient - User managementEach client extends the BaseVXOlympusClient class and inherits common functionality like:
The SDK uses standard error handling mechanisms:
try {
const result = await userClient.loginPost({
username: 'admin@thingsboard.org',
password: 'wrong-password'
});
} catch (error) {
if (error instanceof Error) {
console.error('API Error:', error.message);
}
}
All request and response types are fully typed:
// TypeScript will show all available properties and their types
const deviceInfo = await deviceClient.getDeviceInfoByIdUsingGET({
deviceId: 'your-device-id'
});
// deviceInfo will be fully typed with all properties
console.log(deviceInfo.name);
console.log(deviceInfo.type);
npm installnpm run buildnpm testMIT