Registry / iot / wegnology-rest

wegnology-rest

JSON →
library2.12.5jsnpmunverified

The official REST API client for the WEGnology IoT platform (formerly Losant). Version 2.12.5 is the latest stable release, updated irregularly. Provides an easy way to interact with all WEGnology API endpoints, supporting both Node.js (v0.12+) and browser environments. Uses Axios under the hood. Differentiators: it is the first-party client maintained by WEGnology, offering direct support for device and user authentication, promise and callback interfaces, and full coverage of the platform API. Compared to generic HTTP clients, it abstracts authentication and provides resource-specific methods.

npm install wegnology-rest
INSTALL
IMPORT
SIG · WEGNOLOGY-REST
W
wegnology-rest
iotjavascriptv2.12.5
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.

createClient
import { createClient } from 'wegnology-rest';
const wegnology = require('wegnology-rest'); const client = wegnology.createClient();
Default export is the module itself; createClient is a named export (or property). In CommonJS, require returns the module object, so you must call .createClient() on it. In ESM, use named import.
default
import wegnology from 'wegnology-rest'; const client = wegnology.createClient();
const { default: wegnology } = require('wegnology-rest');
ESM default import works but requires destructuring .createClient from it. CommonJS require returns the module, not a default property.
Client
import { createClient } from 'wegnology-rest'; const client = createClient();
import { Client } from 'wegnology-rest';
There is no exported 'Client' class; only 'createClient' function. The return type is an instance of the internal Client class.

Authenticates as a device and sends a state update. Uses environment variables for credentials.

// Install: npm install wegnology-rest import { createClient } from 'wegnology-rest'; const client = createClient(); client.auth.authenticateDevice({ credentials: { deviceId: process.env.DEVICE_ID ?? '', key: process.env.APP_KEY ?? '', secret: process.env.APP_SECRET ?? '', }, }).then((response) => { client.setOption('accessToken', response.token); const appId = response.applicationId; return client.device.sendState({ deviceId: process.env.DEVICE_ID ?? '', applicationId: appId, deviceState: { data: { temperature: 25.5 } }, }); }).then((response) => { console.log('State sent:', response); }).catch((error) => { console.error('Error:', error); });
Debug
Known issues
gotchaThe module is designed for both Node.js and browser, but the default export is a function (createClient) attached to the module object. In CommonJS, require('wegnology-rest') returns an object with createClient as a method. You cannot call require('wegnology-rest')() directly.
fix
Use: const { createClient } = require('wegnology-rest'); or const client = require('wegnology-rest').createClient();
affects: >=1.0.0
deprecatedCallbacks are supported but deprecated in favor of promises. The documentation shows both patterns, but promise usage is recommended.
fix
Use .then() and .catch() instead of callbacks.
affects: >=2.0.0
gotchaThe access token must be set via setOption('accessToken', token) after authentication. Failing to set the token for subsequent requests will result in 401 Unauthorized errors.
fix
After authentication, call client.setOption('accessToken', response.token);
affects: >=1.0.0
breakingIn version 2.0.0, the method names changed from camelCase to dot-delimited resource names. For example, client.auth.authenticateDevice replaced the previous client.auth_authenticateDevice.
fix
Use the new API structure: client.resource.action(). Refer to migration guide.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: client.auth.authenticateDevice is not a function
Using an older version (<2.0.0) where the method name is different (e.g., client.auth_authenticateDevice).
fix
Update to version 2.0.0 or later, or use the old method name for older versions.
Error: Request failed with status code 401
Missing or expired access token. Token not set after authentication.
fix
After authenticateDevice, store the token via client.setOption('accessToken', response.token).
Module not found: Can't resolve 'wegnology-rest'
Using ESM import but the package is not installed or the import path is incorrect.
fix
Run npm install wegnology-rest. Then use import { createClient } from 'wegnology-rest';
TypeError: wegnology is not a function
CommonJS code calling require('wegnology-rest')() incorrectly.
fix
Use const { createClient } = require('wegnology-rest'); const client = createClient();
Upgrade
Version history
2.12.5latest on npm
Audit
Dependencies
axiosrequiredUsed for making HTTP requests to the WEGnology API.
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
wegnology-rest — npm install wegnology-rest · libregistry