Scripting with phyware¶
Basic Shell Script Pattern¶
#!/usr/bin/env bash
set -euo pipefail
export PHYCLOUD_URL="${PHYCLOUD_URL:-https://cloud.phyware.io}"
export PHYCLOUD_API_KEY="${PHYCLOUD_API_KEY:?Must set PHYCLOUD_API_KEY}"
# Ingest an event
phyware cloud events send \
--source-id "$SOURCE_ID" \
--payload "$(cat event.json)"
Environment Variables¶
Set defaults in your CI/CD environment or .env file:
PHYCLOUD_URL=https://cloud.phyware.io
PHYCLOUD_API_KEY=phk_live_...
PHYCOMP_URL=https://comp.phyware.io
PHYCOMP_API_KEY=phk_comp_...
Error Handling¶
phyware uses structured exit codes:
| Code | Meaning |
|---|---|
0 | Success |
1 | Generic / connection error |
2 | Authentication / authorisation error |
3 | Resource not found |
4 | Validation error |
5 | Server-side error |
Retry Pattern¶
retry() {
local n=0
until [ "$n" -ge 3 ]; do
"$@" && return
n=$((n+1))
sleep $((2**n))
done
return 1
}
retry phyware cloud events send --source-id src_xyz --payload '{}'
Batch Processing¶
# Ingest all JSON files in a directory
for f in events/*.json; do
phyware cloud events send --source-id "$SOURCE_ID" --payload "$(cat "$f")"
done
# Or use batch mode for efficiency
phyware cloud events batch --file events.ndjson