Call the API
Each example discovers an organization and hall, selects a registered sensor, and reads up to ten uncompensated raw frames from the last five minutes. The token stays in an environment variable and is never printed.
Before you run an example
Store the once-only token outside the project, restrict the file, then load it into the current process. Do not commit either the token or an .env file that contains it.
install -d -m 700 "$HOME/.config/butlr"
chmod 600 "$HOME/.config/butlr/organization-api.token"
export BUTLR_DC_API_TOKEN="$(<"$HOME/.config/butlr/organization-api.token")"
export BUTLR_DC_API_BASE='https://api.datacenter.butlr.io'Shell
Requires Bash or Zsh, curl, and jq.
#!/usr/bin/env bash
set -euo pipefail
: "${BUTLR_DC_API_TOKEN:?Set BUTLR_DC_API_TOKEN first}"
BUTLR_DC_API_BASE="${BUTLR_DC_API_BASE:-https://api.datacenter.butlr.io}"
graphql() {
curl --fail-with-body --silent --show-error \
"$BUTLR_DC_API_BASE/graphql" \
--header "Authorization: Bearer $BUTLR_DC_API_TOKEN" \
--header 'Content-Type: application/json' \
--data "$1"
}
inventory=$(graphql '{"query":"query OrganizationInventory { orgs { id name } dataHalls { id name } }"}')
if jq -e '.errors | length > 0' >/dev/null 2>&1 <<<"$inventory"; then
jq '.errors' <<<"$inventory" >&2
exit 1
fi
hall_id="${BUTLR_DC_HALL_ID:-$(jq -er '.data.dataHalls[0].id' <<<"$inventory")}"
sensor_request=$(jq -cn --arg hallId "$hall_id" '{
query: "query HallSensors($hallId: ID!) { sensors(hallId: $hallId) { id kind mac serial model status } }",
variables: {hallId: $hallId}
}')
sensors=$(graphql "$sensor_request")
if jq -e '.errors | length > 0' >/dev/null 2>&1 <<<"$sensors"; then
jq '.errors' <<<"$sensors" >&2
exit 1
fi
sensor_key=$(jq -er 'first(
.data.sensors[] |
if .kind == "wireless_mac" then .mac
elif .kind == "wired_serial" then .serial
else empty end |
select(. != null and . != "")
)' <<<"$sensors")
to_ms="$(( $(date +%s) * 1000 ))"
from_ms="$(( to_ms - 300000 ))"
curl --fail-with-body --silent --show-error --get \
"$BUTLR_DC_API_BASE/v1/sensors/$sensor_key/frames" \
--header "Authorization: Bearer $BUTLR_DC_API_TOKEN" \
--data-urlencode "from=$from_ms" \
--data-urlencode "to=$to_ms" \
--data-urlencode 'limit=10' \
--data-urlencode 'compensate=0' |
jq '{key, kind, tier, from, to, count, total, sampled, missing, compensated}'Remove the final jq projection when your application is ready to process the full frames[].data matrices.
Python
Uses only the Python 3 standard library.
JavaScript
Requires Node.js 18 or later for the built-in fetch implementation.
Production safeguards
Keep the token in a server-side process. Never run these calls from a public browser bundle.
Re-run discovery instead of assuming that hall ownership or sensor registration never changes.
Keep
compensate=0when the integration needs the original device matrix.Treat an empty frame window as a valid
200response and inspectmissing.Use bounded windows and deliberate polling; the archive endpoint is not a live stream.
Authentication — Protect, rotate, and revoke an Organization API Token.
Raw frame contract — Review response fields, limits, and matrix format.
Last updated