Registry / iot / sitewhere-rest-api

sitewhere-rest-api

JSON →
library3.0.2jsnpmunverified

TypeScript client library for SiteWhere IoT platform REST APIs (v3.0.2). Provides strongly-typed access to all SiteWhere API endpoints including device management, authentication, tenant operations, and system administration. Built on Axios for HTTP, with full TypeScript definitions for request/response objects. Released under proprietary license. Differentiated by full type safety and complete API coverage compared to raw HTTP clients.

npm install sitewhere-rest-api
INSTALL
IMPORT
SIG · SITEWHERE-REST-API
S
sitewhere-rest-api
iotjavascriptv3.0.2
harness data pending
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);
Debug
Known issues
breakingPackage is ESM-only. Using require() will fail.
fix
Use import syntax or dynamic import.
affects: >=3.0
deprecatedAuthAPI.Jwt.getJwt() method may be deprecated in future versions in favor of a unified authentication flow.
fix
Monitor SiteWhere documentation for updated authentication patterns.
affects: 3.0.x
gotchaJWT must be refreshed periodically; the library does not auto-refresh tokens.
fix
Implement token refresh logic in application code.
affects: all
gotchaAll API methods are async and return AxiosResponse; you must access .data to get the response body.
fix
Use resp.data to obtain the typed response object.
affects: all
gotchaTenant authentication token ('sitewhere01234567890' in examples) is required; missing it causes 401 errors.
fix
Provide the correct tenant auth token issued by SiteWhere admin.
affects: all
Errors
Common errors & fixes
Cannot find module 'sitewhere-rest-api' or its corresponding type declarations.
Missing npm install or outdated TypeScript configuration.
fix
Run '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.
fix
Use 'import * as SiteWhere from "sitewhere-rest-api"'.
AxiosError: Request failed with status code 401
Invalid JWT or missing tenant auth token.
fix
Verify JWT is obtained correctly and tenant token matches SiteWhere configuration.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
axiosrequiredHTTP client for all REST API calls
Agent activity
23 hits · last 30 days
node
18
Amazon
1
Resources
sitewhere-rest-api — npm install sitewhere-rest-api · libregistry