Support
All articles

Summarize managed devices by platform

Build a small inventory report from the public Devices endpoint.

Topic
Developer API
Reading time
2 min
Share

Use GET /external/v1/devices to see the mix of operating systems in one Trio company. The example outputs a count for each platform so it can feed a simple report or inventory check.

Before you start

You need Node.js 22 or later and an Inventory key. Set TRIO_API_KEY and TRIO_API_URL using the developer quickstart.

Read every page and count devices

Save the example as device-platform-summary.mjs, then run node device-platform-summary.mjs. The List devices response returns items, offset, limit, and total. Use the offset and limit returned by Trio to calculate the next page.

const apiKey = process.env.TRIO_API_KEY;
const apiUrl = process.env.TRIO_API_URL;
const regions = new Set(["https://coreapi.trio.so", "https://coreapi-eu.trio.so"]);

if (!apiKey || !regions.has(apiUrl)) {
  throw new Error("Set TRIO_API_KEY and the Trio base URL for your region.");
}

const platformByDevice = new Map();
const url = new URL("/external/v1/devices", apiUrl);
url.searchParams.set("limit", "200");

for (let offset = 0; ; ) {
  url.searchParams.set("offset", String(offset));
  const response = await fetch(url, {
    headers: { "X-API-Key": apiKey, Accept: "application/json" },
    redirect: "error",
    signal: AbortSignal.timeout(30_000),
  });
  if (!response.ok) throw new Error(`List devices failed with HTTP ${response.status}.`);

  const page = await response.json();
  for (const device of page.items) {
    platformByDevice.set(device.id, device.platform || "unknown");
  }

  const nextOffset = page.offset + page.limit;
  if (page.items.length === 0 || nextOffset >= page.total) break;
  if (nextOffset <= offset) throw new Error("Device pagination did not advance.");
  offset = nextOffset;
}

const counts = new Map();
for (const platform of platformByDevice.values()) {
  counts.set(platform, (counts.get(platform) ?? 0) + 1);
}
console.log(JSON.stringify(Object.fromEntries(counts), null, 2));

The output contains platform names and counts. Device IDs are held in memory to avoid counting a device twice if it appears on more than one page. A changing fleet can shift results during an offset-based scan, so rerun the report when you need fresher counts.

For device fields and response codes, see the List devices reference. For troubleshooting authentication or paginating user results, see the developer quickstart and the inventory guide.