This is the official node.js client for the StreamLabs Developer API.
See the StreamLabs Developer API docs
npm i @streamlabswater/stream
The package needs to configured with your accounts API Key available when you login into your http://my.streamlabswater.com account.
const Stream = require('@streamlabswater/stream')
const stream = new Stream('YOUR_STREAMLABSWATER_API_KEY')
or using ES modules
import Stream from '@streamlabswater/stream'
const stream = new Stream('YOUR_STREAMLABSWATER_API_KEY')
All of the methods return Promises and use async/wait
Start by fetching all your locations
const example = async () => {
try {
const locations = await stream.locations.get()
console.log('LOCATIONS', locations)
} catch (e) {
console.error(e)
}
}
A locationId
is required to fetch details of a location, water usage and for updating homeAway.
// ...
const locationId = 'ae926a02...dbc8'
const location = await stream.location.get(locationId)
// ...
Currently you can only update the homeAway mode of the location When updating a location the response is always the updated location details
// ...
const locationId = 'ae926a02...dbc8'
const options = {
homeAway: 'away'
}
const location = await stream.location.update(locationId, options)
// ...
If you choose to recieve notifications when alerts become active or end for a location, you need to provide a valid url endpoint where the StreamLabs service will send the notifications. The following methods wrap the corresponding StreamLabs api endpoints as descriped in the Subscribe to Location Alerts section in the docs
// ...
const locationId = 'ae926a02...dbc8'
const endpoint = 'https://example-endpoint.com'
const subscription = await stream.location.subscribe(locationId, endpoint)
// ...
Once you recieve the confirmationToken
via your endpoint, update the subscription to start recieving alerts.
// ...
const subscriptionId = '3bb2255b...2a48'
const confirmationToken = 'r3vHQ2NXpkK...uuyt'
const subscription = await stream.subscription.update(subscriptionId, confirmationToken)
// ...
// ...
const locationId = 'ae926a02...dbc8'
const subscriptions = await stream.location.subscriptions.get(locationId)
// ...
// ...
const subscriptionId = '3bb2255b...2a48'
const subscription = await stream.subscription.get(subscriptionId)
// ...
// ...
const subscriptions = await stream.subscriptions.get()
// ...
// ...
const subscriptionId = '3bb2255b...2a48'
const subscription = await stream.subscription.delete(subscriptionId)
// ...
This method will throw an Exception if the delete fails else returns an empty body
// ...
const locationId = 'ae926a02...dbc8'
const waterUsageSummary = await stream.location.waterUsage.summary.get(locationId)
// ...
At the very minimum you need to provide a startTime
for the readings you want to retrieve.
// ...
const locationId = 'ae926a02...dbc8'
/**
* All time params should be Date Objects or ISO Formatted date strings
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
*/
const options = {
startTime: new Date(),
endTime: new Date(), // optional
groupBy,
page,
perPage
}
const waterUsage = await stream.location.waterUsage.get(locationId, options)
// ...