{"id":48427,"library":"losant-rest","title":"Losant REST API Client","description":"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.","status":"active","version":"4.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/Losant/losant-rest-js","tags":["javascript","IoT","platform","api","REST"],"install":[{"cmd":"npm install losant-rest","lang":"bash","label":"npm"},{"cmd":"yarn add losant-rest","lang":"bash","label":"yarn"},{"cmd":"pnpm add losant-rest","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for HTTP communication under the covers","package":"axios","optional":false}],"imports":[{"note":"The package exports a default object with a `createClient` function. Named import `createClient` will not work.","wrong":"import { createClient } from 'losant-rest'","symbol":"default","correct":"import api from 'losant-rest'"},{"note":"CommonJS require works but is discouraged. Always use ESM import for consistency.","wrong":"const api = require('losant-rest');","symbol":"createClient","correct":"import api from 'losant-rest'; const client = api.createClient({...})"},{"note":"TypeScript types are available via type-only imports. Value imports are not supported.","wrong":"import { ClientOptions } from 'losant-rest'","symbol":"types","correct":"import type { ClientOptions, DeviceState } from 'losant-rest'"}],"quickstart":{"code":"import api from 'losant-rest';\n\nconst client = api.createClient();\n\nasync function main() {\n  const { applicationId, token } = await client.auth.authenticateDevice({\n    credentials: {\n      deviceId: process.env.DEVICE_ID ?? '',\n      key: process.env.ACCESS_KEY ?? '',\n      secret: process.env.ACCESS_SECRET ?? ''\n    }\n  });\n\n  client.setOption('accessToken', token);\n\n  const state = {\n    data: { temperature: 23.5 },\n    time: Date.now()\n  };\n\n  await client.device.sendState({\n    deviceId: process.env.DEVICE_ID ?? '',\n    applicationId: applicationId,\n    deviceState: state\n  });\n}\n\nmain().catch(console.error);","lang":"javascript","description":"Authenticates as a device, sets the access token, and sends device state to the Losant platform."},"warnings":[{"fix":"Use `await` or `.then()` instead of a callback.","message":"In version 2.x, `client.auth.authenticateDevice` required a callback. In version 3+, it returns a promise.","severity":"breaking","affected_versions":">=2.0 <3.0"},{"fix":"Upgrade Node.js to v20 or later.","message":"Node.js version 18 and below are no longer supported as of losant-rest@4.0.0.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use `import api from 'losant-rest'` instead.","message":"The `require('losant-rest')` CommonJS pattern is deprecated in favor of ESM imports.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Always import the default export: `import api from 'losant-rest'`.","message":"The default export is an object with a `createClient` function. Directly importing `createClient` as a named export will result in `undefined`.","severity":"gotcha","affected_versions":"*"},{"fix":"Use `import type { ClientOptions } from 'losant-rest'`.","message":"When using TypeScript, types must be imported with `import type` because they are not re-exported as values.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"search_vec":"'4.2.0':18 'api':3,13,46,72,78 'authent':51 'axio':26 'browser':33 'client':4,6 'coverag':42 'createcli':68 'current':14 'devic':48 'differenti':39 'document':74 'environ':36 'export':69 'extens':71 'full':41 'hood':29 'iot':10,76 'javascript':75 'javascript/typescript':5 'key':38 'librari':62 'losant':1,9,45,59 'maintain':57 'minim':64 'node.js':35 'npm':22 'packag':23 'platform':11,77 'promis':53 'provid':40 'refer':73 'releas':19 'rest':2,12,79 'return':52 'singl':67 'stabl':15 'support':31,47 'use':25 'user':50 'v20':37 'version':16","created_at":"2026-06-07T16:56:36.112968+00:00","updated_at":"2026-06-07T16:56:36.112968+00:00","problems":[{"fix":"Use `import api from 'losant-rest'` and then `api.createClient()`.","cause":"Incorrect import: using named import `createClient` instead of default import.","error":"TypeError: api.createClient is not a function"},{"fix":"Run `npm install losant-rest` and ensure Node.js v20+.","cause":"Package not installed or Node.js version too old (pre-20) for ESM.","error":"Cannot find module 'losant-rest'"},{"fix":"Upgrade to losant-rest@3.0.0 or later and use promises.","cause":"Using a version prior to 3.0 where the method required a callback, not a promise.","error":"TypeError: client.auth.authenticateDevice(...) is not a function","affected_versions":"<3.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/Losant/losant-rest-js#readme","github":"https://github.com/Losant/losant-rest-js","docs":null,"changelog":null,"pypi":null,"npm":"losant-rest","openapi_spec":null,"status_page":null,"smithery":null,"categories":["iot","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}