Skip to content

bluebotdev/bluebot-examples-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bluebot-examples-typescript

Runnable TypeScript examples that call the Bluebot Management API using a fully typed client generated with openapi-typescript and openapi-fetch.

Each script in src/examples/ corresponds 1:1 to an example documented in the Bluebot Developer Center.

Quickstart

git clone https://github.com/bluebot/bluebot-typescript-examples.git
cd bluebot-typescript-examples
npm install
cp .env.example .env
# fill in BLUEBOT_API_KEY (and BLUEBOT_DEVICE_ID for the flow examples)
npm run list-organizations

How types are generated

Types are generated once from the management API's OpenAPI document and committed to src/schema.d.ts.

npm run openapi:generate

That runs:

openapi-typescript https://prod.bluebot.com/management/v1/api-json -o ./src/schema.d.ts

Re-run it whenever the API spec changes — TypeScript will surface breaking changes at compile time.

How auth works

src/client.ts creates a single typed client and registers a middleware that attaches the bluebot-api-key header to every outbound request. The key is read from BLUEBOT_API_KEY in the environment.

Scripts

Script Endpoint Notes
npm run list-organizations GET /management/v1/organizations/mine The org the API key is scoped to.
npm run list-devices GET /management/v1/device Page through devices.
npm run historical-last-hour GET /management/v1/flow/datapoints/{id} 5-minute buckets, last hour.
npm run historical-raw-5min GET /management/v1/flow/datapoints/{id} Raw rows, last 5 minutes.
npm run historical-daily-totals GET /management/v1/flow/datapoints/{id} Daily totals over the past 30 days.
npm run historical-count-only GET /management/v1/flow/datapoints/{id} Just the row count.
npm run adaptive-1day GET /management/v1/flow/adaptive/{id} ~500 datapoints over 24 hours.
npm run adaptive-7day GET /management/v1/flow/adaptive/{id} ~1000 datapoints over 7 days.
npm run adaptive-30day-tz GET /management/v1/flow/adaptive/{id} 30 days, in your timezone.
npm run latest-all-metrics GET /management/v1/flow/latest Uptime, last-seen, quality.
npm run latest-lastseen-multi GET /management/v1/flow/latest Just last-seen across many devices.
npm run latest-uptime-1h GET /management/v1/flow/latest Uptime over the past hour.

Environment

Var Required by Description
BLUEBOT_API_KEY every script Your management API key.
BLUEBOT_API_BASE_URL every script API root. Defaults to https://prod.bluebot.com. Set to https://prod.bluebot.com to hit prod.
BLUEBOT_DEVICE_ID historical-*, adaptive-* A single device id (UUID, serial number, or NUID).
BLUEBOT_DEVICE_IDS latest-* Comma-separated device ids.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors