Skip to content

API Examples

Chris Nighswonger edited this page Apr 2, 2026 · 2 revisions

API Examples

Base URL examples assume local default:

BASE=http://localhost:8000

Current Conditions

curl -s "$BASE/api/current" | jq .

Station Status

curl -s "$BASE/api/station" | jq .

History Query

curl -s "$BASE/api/history?sensor=outside_temp&start=2026-03-01T00:00:00Z&end=2026-03-02T00:00:00Z&resolution=5m" | jq .

Export CSV

curl -L "$BASE/api/export?sensor=outside_temp&start=2026-03-01T00:00:00Z&end=2026-03-02T00:00:00Z&resolution=hourly" -o outside_temp.csv

Config Read

curl -s "$BASE/api/config" | jq .

Config Update

Enable nowcast and spray features:

curl -s -X PUT "$BASE/api/config" \
  -H "Content-Type: application/json" \
  -d '[
    {"key":"nowcast_enabled","value":true},
    {"key":"spray_enabled","value":true}
  ]' | jq .

Setup: List Serial Ports

For serial-connected stations:

curl -s "$BASE/api/setup/serial-ports" | jq .

Setup: Probe Port

Test a serial connection (Davis legacy/Vantage stations):

curl -s -X POST "$BASE/api/setup/probe" \
  -H "Content-Type: application/json" \
  -d '{"port":"/dev/ttyUSB0","baud_rate":2400}' | jq .

Setup: Auto Detect

Scan for connected station hardware (serial and network):

curl -s -X POST "$BASE/api/setup/auto-detect" | jq .

Hardware: Config Read

Read station hardware configuration (capability-dependent — not all station types support this):

curl -s "$BASE/api/weatherlink/config" | jq .

Hardware: Force Archive

Trigger an archive write on the station (capability-dependent):

curl -s -X POST "$BASE/api/weatherlink/force-archive" | jq .

Forecast and Astronomy

curl -s "$BASE/api/forecast" | jq .
curl -s "$BASE/api/astronomy" | jq .

Nowcast: Read, Generate, Status

curl -s "$BASE/api/nowcast" | jq .
curl -s -X POST "$BASE/api/nowcast/generate" | jq .
curl -s "$BASE/api/nowcast/status" | jq .
curl -s "$BASE/api/nowcast/presets" | jq .

Nowcast: Alerts, History, Knowledge

curl -s "$BASE/api/nowcast/alerts" | jq .
curl -s "$BASE/api/nowcast/history?limit=10" | jq .    # local mode only
curl -s "$BASE/api/nowcast/knowledge" | jq .            # local mode only

Spray: Products and Quick Evaluation

curl -s "$BASE/api/spray/products" | jq .

# evaluate product id 1
curl -s -X POST "$BASE/api/spray/evaluate" \
  -H "Content-Type: application/json" \
  -d '{"product_id":1}' | jq .

Usage and DB Admin

curl -s "$BASE/api/usage/status" | jq .
curl -s "$BASE/api/usage/local" | jq .
curl -s "$BASE/api/db-admin/stats" | jq .

Output Formats

curl -s "$BASE/api/metar" | jq .
curl -s "$BASE/api/aprs" | jq .

Backgrounds

curl -s "$BASE/api/backgrounds" | jq .

Logs

curl -s "$BASE/api/logs?level=WARNING&limit=50" | jq .

Map Data

# Nearby stations (default radius and limit)
curl -s "$BASE/api/map/nearby-stations" | jq .

# Nearby stations with custom radius and zoom
curl -s "$BASE/api/map/nearby-stations?radius=200&limit=100&zoom=10" | jq .

# NWS alert polygons
curl -s "$BASE/api/map/alerts" | jq .

# Pressure isobar contours
curl -s "$BASE/api/map/isobars" | jq .

Backup

# Trigger a backup
curl -s -X POST "$BASE/api/backup" | jq .

# List existing backups
curl -s "$BASE/api/backup/list" | jq .

# Download a backup
curl -L "$BASE/api/backup/download/<backup-name>" -o backup.tar.gz

# Delete a backup
curl -s -X DELETE "$BASE/api/backup/<backup-name>" | jq .

Database Export (Legacy)

curl -L "$BASE/api/db-admin/export/backup" -o kanfei-backup.db

WebSocket Quick Test

If wscat is installed:

wscat -c ws://localhost:8000/ws/live

You should receive an initial connection_status message, then live events.

Clone this wiki locally