Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SiteWhere (namespace)
✓ import * as SiteWhere from 'sitewhere-rest-api'
✗ import SiteWhere from 'sitewhere-rest-api'
Package exports a namespace, not a default export.
IDeviceCreateRequest
✓ import { IDeviceCreateRequest } from 'sitewhere-rest-api'
✗ import { DeviceCreateRequest } from 'sitewhere-rest-api'
Interface names are prefixed with 'I'.
Auth.createJwtRequest
✓ import { Auth } from 'sitewhere-rest-api'; Auth.createJwtRequest(...)
✗ import { createJwtRequest } from 'sitewhere-rest-api'
createJwtRequest is a static method on the Auth class.
API.Devices.createDevice
✓ import { API } from 'sitewhere-rest-api'; API.Devices.createDevice(axios, request)
✗ import { createDevice } from 'sitewhere-rest-api'
Top-level API function is under API.Devices namespace.
Authenticates with SiteWhere server using basic auth, obtains JWT, then creates a device on the default tenant.
import * as SiteWhere from 'sitewhere-rest-api';
import { AxiosResponse, AxiosInstance } from 'axios';
import { IDeviceCreateRequest, IDevice } from 'sitewhere-rest-api';
async function createDevice() {
const auth: AxiosInstance = SiteWhere.Auth.createBasicAuthRequestForCredentials(
'http://localhost:8080/sitewhere/authapi',
process.env.SITEWHERE_USER ?? 'admin',
process.env.SITEWHERE_PASSWORD ?? 'password'
);
const jwtResp: AxiosResponse<any> = await SiteWhere.AuthAPI.Jwt.getJwt(auth);
const jwt: string = jwtResp.headers['x-sitewhere-jwt'];
const axios: AxiosInstance = SiteWhere.Auth.createJwtRequest(
'http://localhost:8080/sitewhere/api',
jwt,
'default',
'sitewhere01234567890'
);
const request: IDeviceCreateRequest = {
deviceTypeToken: 'ipad',
token: '123-TEST-4989485938',
comments: 'Created via REST API'
};
const resp: AxiosResponse<IDevice> = await SiteWhere.API.Devices.createDevice(axios, request);
const device: IDevice = resp.data;
console.log(`Created ${device.token} on ${device.createdDate}`);
}
createDevice().catch(console.error);
Errors
Common errors & fixes
Cannot find module 'sitewhere-rest-api' or its corresponding type declarations.
Missing npm install or outdated TypeScript configuration.
fixRun 'npm install sitewhere-rest-api' and ensure tsconfig.json includes 'node_modules' in 'moduleResolution'.
TypeError: SiteWhere.Auth.createJwtRequest is not a function
Incorrect import; likely imported namespace incorrectly.
fixUse 'import * as SiteWhere from "sitewhere-rest-api"'.
AxiosError: Request failed with status code 401
Invalid JWT or missing tenant auth token.
fixVerify JWT is obtained correctly and tenant token matches SiteWhere configuration.
Audit
Dependencies
axiosrequiredHTTP client for all REST API calls