{"id":18654,"library":"particle-api-js","title":"Particle API JS","description":"JavaScript library for the Particle Cloud API, usable in Node.js (v16+) and browser environments. Current stable version is v12.0.2, released via npm. Actively maintained with releases every few months. Written in TypeScript with full type declarations. Covers all Particle IoT device interactions: authentication, device listing, variable/function access, event streaming, firmware management, and more. Differentiates from raw fetch/axios by wrapping the entire Particle REST API with typed request options and responses, handling authentication and pagination internally. Ships both ESM and UMD builds (CDN via jsDelivr). Major v12.0.0 was a TypeScript migration; v11.0.0 removed token list/delete APIs and query access_token support.","status":"active","version":"12.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/particle-iot/particle-api-js","tags":["javascript","particle","library","spark","api","typescript"],"install":[{"cmd":"npm install particle-api-js","lang":"bash","label":"npm"},{"cmd":"yarn add particle-api-js","lang":"bash","label":"yarn"},{"cmd":"pnpm add particle-api-js","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for multipart/form-data requests (e.g., firmware uploads)","package":"form-data","optional":false}],"imports":[{"note":"Default export is the Particle class. Named export for class was removed in v12.0.0 TypeScript migration.","wrong":"const { Particle } = require('particle-api-js')","symbol":"Particle","correct":"import Particle from 'particle-api-js'"},{"note":"Type imports should use `import type` to avoid runtime inclusion. Available since v12.0.0.","wrong":"import { DeviceInfo } from 'particle-api-js'","symbol":"DeviceInfo","correct":"import type { DeviceInfo } from 'particle-api-js'"},{"note":"","wrong":"","symbol":"LoginResponse","correct":"import type { LoginResponse } from 'particle-api-js'"}],"quickstart":{"code":"import Particle from 'particle-api-js';\nimport type { DeviceInfo, LoginResponse } from 'particle-api-js';\n\nconst particle = new Particle({ auth: process.env.PARTICLE_TOKEN ?? '' });\n\nasync function listDevices() {\n  try {\n    const response = await particle.listDevices();\n    console.log('Devices:', response.body);\n  } catch (error) {\n    console.error('Error:', error);\n  }\n}\n\nasync function loginAndCall() {\n  const loginResp = await particle.login({\n    username: process.env.EMAIL ?? '',\n    password: process.env.PASSWORD ?? ''\n  });\n  console.log('Token:', loginResp.body.access_token);\n  // Re-create client with new token\n  const particleAuthed = new Particle({ auth: loginResp.body.access_token });\n  const device = await particleAuthed.getDevice({ deviceId: 'abc123' });\n  console.log('Device name:', device.body.name);\n}\n\nlistDevices();","lang":"typescript","description":"Shows how to instantiate Particle client, authenticate via login, list devices, and fetch a single device with full TypeScript typing."},"warnings":[{"fix":"Use Particle Cloud API directly or alternative authentication flow.","message":"deleteAccessToken and listAccessTokens methods are deprecated in v11.0.0 and removed from v12?","severity":"deprecated","affected_versions":">=11.0.0 <12.0.0"},{"fix":"Pass token via Authorization header (handled automatically via constructor auth option).","message":"Query string access_token parameter is no longer supported.","severity":"breaking","affected_versions":">=11.0.0"},{"fix":"Use ES module import from npm for typed usage.","message":"In browsers, using the CDN builds (<script> tag) exposes global variable `Particle` but TypeScript types are not available.","severity":"gotcha","affected_versions":">=8.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install particle-api-js` or `yarn add particle-api-js`","cause":"Package not installed via npm","error":"Error: Cannot find module 'particle-api-js'"},{"fix":"Use `import Particle from 'particle-api-js'` then `new Particle()`","cause":"Incorrect import (likely named import instead of default)","error":"TypeError: particle.listDevices is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}