@letsparky/api-client
v1.0.2
Published
TypeScript SDK for Letsparky API
Downloads
10
Readme
Letsparky TypeScript API Client
A TypeScript client for interacting with the Letsparky User API.
Installation
npm install @letsparky/api-clientUsage
import { LetsparkyClient } from 'letsparky-api-client';
// Initialize the client
const client = new LetsparkyClient({
baseUrl: 'https://api.letsparky.com',
// Either use an API key
apiKey: 'your-api-key',
// Or use access token (typically after login)
// accessToken: 'your-access-token',
// refreshToken: 'your-refresh-token'
});Authentication
Login with Email and Password
const loginResponse = await client.auth.login({
email: '[email protected]',
password: 'password123'
});
// The client automatically stores the tokens
console.log(loginResponse.userId);
console.log(loginResponse.accessToken);Refresh Token
const refreshResponse = await client.auth.refreshToken();
console.log(refreshResponse.accessToken);
console.log(refreshResponse.refreshToken);Set Authentication Manually
// Set access token
client.setAccessToken('your-access-token', 'your-refresh-token');
// Or set API key
client.setApiKey('your-api-key');Device Management
Create a Device
const createDeviceResponse = await client.device.createDevice({
serialNo: 'DEVICE123',
type: 'PARKY_TCP',
terminalArmonId: 'ARMON123',
firmwareVersion: '1.0.0',
macAddress: '00:11:22:33:44:55',
imeiNumber: '123456789012345',
blePassword: 'password123'
});
console.log(createDeviceResponse.deviceId);Get Device by ID
const device = await client.device.getDeviceById('device-id');Get Device by QR Data
const device = await client.device.getDeviceByQRData('qr-data');User Device Management
Get User Devices
const userDevices = await client.userDevice.getUserDevices();Add Owner to Device
const addDeviceResponse = await client.userDevice.addOwnerToDevice({
serialNo: 'DEVICE123',
nickName: 'My Device',
qrData: 'qr-data',
terminalType: 'type',
photo: 'base64-encoded-photo',
geoLat: 40.7128,
geoLng: -74.0060
});
console.log(addDeviceResponse.id);
console.log(addDeviceResponse.deviceId);Factory Reset a Device
const resetResponse = await client.userDevice.factoryResetDevice('device-id');
console.log(resetResponse.success);Get User Device by Device ID
const userDevice = await client.userDevice.getUserDeviceByDeviceId('device-id');Get User Device by QR Data
const userDevice = await client.userDevice.getUserDeviceByQrData('qr-data');TCP Device Operations
Get Operational Status
const status = await client.tcpDevice.getOperationalStatus('device-id');
console.log(status.operationalStatus);
console.log(status.batteryVoltage);Block Device
const blockResponse = await client.tcpDevice.blockDevice('device-id');
console.log(blockResponse.command);Unblock Device
const unblockResponse = await client.tcpDevice.unblockDevice('device-id');
console.log(unblockResponse.command);Webhook Configuration
Create Webhook Configuration
const webhookConfig = await client.webhookConfiguration.createWebhookConfiguration({
callbackUrl: 'https://your-callback-url.com/webhook'
});Update Webhook Configuration
const updatedConfig = await client.webhookConfiguration.updateWebhookConfiguration({
id: 'config-id',
callbackUrl: 'https://your-new-callback-url.com/webhook'
});Get Webhook Configuration
const config = await client.webhookConfiguration.getWebhookConfiguration();
console.log(config.callbackUrl);Error Handling
try {
const response = await client.device.getDeviceById('invalid-id');
} catch (error) {
console.error(error.message);
}Models
The client includes TypeScript interfaces for all request and response objects, ensuring type safety throughout your application.
License
MIT
