Webhook Events

Webhooks let your application receive real-time HTTP POST notifications when events occur in Phosra. Instead of polling the API, register a webhook URL and Phosra will push events to you.

Setting Up Webhooks

Create a webhook subscription for a family:

bash
curl -X POST https://phosra-api.fly.dev/api/v1/webhooks \
  -H "Authorization: Bearer $PHOSRA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "family_id": "FAMILY_UUID",
    "url": "https://yourapp.com/webhooks/phosra",
    "events": [
      "policy.updated",
      "policy.activated",
      "enforcement.completed",
      "enforcement.failed",
      "child.created",
      "compliance.verified",
      "compliance.error"
    ]
  }'

Event Types

EventTrigger
policy.updatedA policy's rules were changed
policy.activatedA policy was activated
policy.pausedA policy was paused
enforcement.completedEnforcement job finished successfully
enforcement.failedEnforcement job failed
enforcement.partialEnforcement succeeded on some platforms, failed on others
child.createdA child was added to the family
child.updatedA child's profile was updated
compliance.verifiedA platform connection was verified
compliance.errorA platform connection failed verification
device.registeredA new device was registered
device.reportA device submitted an activity report

Webhook Payload

Every webhook delivery is a JSON POST with this structure:

json
{
  "event": "enforcement.completed",
  "timestamp": "2026-02-23T14:30:00Z",
  "family_id": "550e8400-e29b-41d4-a716-446655440000",
  "data": {
    "job_id": "660e8400-e29b-41d4-a716-446655440001",
    "child_id": "770e8400-e29b-41d4-a716-446655440002",
    "status": "completed",
    "platforms": [
      {
        "platform_id": "nextdns",
        "rules_applied": 12,
        "rules_skipped": 3,
        "rules_failed": 0
      }
    ]
  }
}

Testing Webhooks

Send a test delivery to verify your endpoint is working:

bash
curl -X POST https://phosra-api.fly.dev/api/v1/webhooks/WEBHOOK_UUID/test \
  -H "Authorization: Bearer $PHOSRA_API_KEY"

Viewing Delivery History

Check past deliveries, including failures and retry attempts:

bash
curl https://phosra-api.fly.dev/api/v1/webhooks/WEBHOOK_UUID/deliveries?limit=20 \
  -H "Authorization: Bearer $PHOSRA_API_KEY"

Retry Behavior

Failed deliveries are retried with exponential backoff:

AttemptDelay
1st retry1 minute
2nd retry5 minutes
3rd retry30 minutes
4th retry2 hours
5th retry12 hours

After 5 failed attempts, the delivery is marked as permanently failed. You can view the next_retry_at timestamp in the delivery record.

Best Practices

  • Respond quickly -- Return a 200 within 5 seconds. Process the payload asynchronously if needed.
  • Verify idempotency -- Webhooks may be delivered more than once. Use the event timestamp and job/resource IDs to deduplicate.
  • Monitor delivery health -- Check the deliveries endpoint periodically for failed deliveries.
  • Use HTTPS -- Webhook URLs must use HTTPS in production.