Registry / iot / losant-rest

losant-rest

JSON →
library4.2.0jsnpmunverified

JavaScript/TypeScript client for the Losant IoT platform REST API. Current stable version is 4.2.0, released as an npm package. It uses Axios under the hood and supports both browser and Node.js environments (v20+). Key differentiators: provides full coverage of the Losant API, supports device and user authentication, returns promises only, and is maintained by Losant itself. The library is minimal with a single `createClient` export and extensive API reference documentation.

npm install losant-rest
INSTALL
IMPORT
SIG · LOSANT-REST
L
losant-rest
iotjavascriptv4.2.0
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.

default
import api from 'losant-rest'
import { createClient } from 'losant-rest'
The package exports a default object with a `createClient` function. Named import `createClient` will not work.
createClient
import api from 'losant-rest'; const client = api.createClient({...})
const api = require('losant-rest');
CommonJS require works but is discouraged. Always use ESM import for consistency.
types
import type { ClientOptions, DeviceState } from 'losant-rest'
import { ClientOptions } from 'losant-rest'
TypeScript types are available via type-only imports. Value imports are not supported.

Authenticates as a device, sets the access token, and sends device state to the Losant platform.

import api from 'losant-rest'; const client = api.createClient(); async function main() { const { applicationId, token } = await client.auth.authenticateDevice({ credentials: { deviceId: process.env.DEVICE_ID ?? '', key: process.env.ACCESS_KEY ?? '', secret: process.env.ACCESS_SECRET ?? '' } }); client.setOption('accessToken', token); const state = { data: { temperature: 23.5 }, time: Date.now() }; await client.device.sendState({ deviceId: process.env.DEVICE_ID ?? '', applicationId: applicationId, deviceState: state }); } main().catch(console.error);
Debug
Known issues
breakingIn version 2.x, `client.auth.authenticateDevice` required a callback. In version 3+, it returns a promise.
fix
Use `await` or `.then()` instead of a callback.
affects: >=2.0 <3.0
breakingNode.js version 18 and below are no longer supported as of losant-rest@4.0.0.
fix
Upgrade Node.js to v20 or later.
affects: >=4.0.0
deprecatedThe `require('losant-rest')` CommonJS pattern is deprecated in favor of ESM imports.
fix
Use `import api from 'losant-rest'` instead.
affects: >=4.0.0
gotchaThe default export is an object with a `createClient` function. Directly importing `createClient` as a named export will result in `undefined`.
fix
Always import the default export: `import api from 'losant-rest'`.
affects: *
gotchaWhen using TypeScript, types must be imported with `import type` because they are not re-exported as values.
fix
Use `import type { ClientOptions } from 'losant-rest'`.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: api.createClient is not a function
Incorrect import: using named import `createClient` instead of default import.
fix
Use `import api from 'losant-rest'` and then `api.createClient()`.
Cannot find module 'losant-rest'
Package not installed or Node.js version too old (pre-20) for ESM.
fix
Run `npm install losant-rest` and ensure Node.js v20+.
TypeError: client.auth.authenticateDevice(...) is not a function
Using a version prior to 3.0 where the method required a callback, not a promise.
fix
Upgrade to losant-rest@3.0.0 or later and use promises.
Upgrade
Version history
4.2.0latest on npm
Audit
Dependencies
axiosrequiredUsed for HTTP communication under the covers
Agent activity
32 hits · last 30 days
node
26
OpenAI (training)
1
Resources
losant-rest — npm install losant-rest · libregistry