Skip to content

Webhooks (Premium)

Real-time webhooks for air quality alerts.

Creating a Webhook

curl -X POST "https://api.airchain.ng/v1/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.com/webhook",
    "events": ["aqi.high", "sensor.offline"],
    "filters": {
      "sensor_id": "NGR-LOS-YAB-001",
      "aqi_threshold": 150
    }
  }'

Event Types

  • aqi.high - AQI exceeds threshold
  • aqi.critical - AQI > 300
  • sensor.offline - Sensor goes offline
  • sensor.online - Sensor comes back online
  • reading.new - New reading available

Payload Format

{
  "event": "aqi.high",
  "timestamp": "2025-11-29T14:35:00Z",
  "data": {
    "sensor_id": "NGR-LOS-YAB-001",
    "aqi": 165,
    "location": "Yaba, Lagos",
    "measurements": {
      "pm25": 55.3,
      "pm10": 88.2
    }
  }
}

Security

Webhooks include X-AirChain-Signature header for verification:

import hmac
import hashlib

def verify_webhook(payload, signature, secret):
    expected = hmac.new(
        secret.encode(),
        payload.encode(),
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, signature)

Upgrade to Premium →