Subscriptions API¶
The Subscriptions API manages event subscriptions and webhook delivery configuration.
Endpoints¶
Method | Endpoint | Description |
---|---|---|
GET | /v1/subscriptions | List subscriptions |
POST | /v1/subscriptions | Create subscription |
PUT | /v1/subscriptions/:id | Update subscription |
DELETE | /v1/subscriptions/:id | Delete subscription |
Create Subscription¶
Subscribe to receive events via webhook.
Request¶
curl -X POST http://localhost/v1/subscriptions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"application": "email-service",
"subscription": "welcome-emails",
"action": "user.created",
"handler": "https://email.myapp.com/webhooks/user-created",
"max_retries": 3
}'
Response¶
{
"data": {
"rowid": 1,
"application": "email-service",
"subscription": "welcome-emails",
"action": "user.created",
"handler": "https://email.myapp.com/webhooks/user-created",
"max_retries": 3,
"timestamped": "2024-12-10T10:30:00Z"
}
}
List Subscriptions¶
Retrieve all subscriptions.
Request¶
Query Parameters¶
Parameter | Type | Description |
---|---|---|
application | string | Filter by application |
action | string | Filter by action |
active | boolean | Filter by active status |
Webhook Delivery¶
When events are published, Amebo delivers them to subscribed endpoints:
Webhook Format¶
{
"event_id": "evt_123",
"action": "user.created",
"payload": {
"id": "user-123",
"email": "john@example.com",
"name": "John Doe"
},
"timestamp": "2024-12-10T10:30:00Z",
"delivery_attempt": 1
}
Headers¶
Content-Type: application/json
Authorization: Bearer webhook-secret
X-Amebo-Event: user.created
X-Amebo-Delivery: evt_123_1
X-Amebo-Signature: sha256=...
Retry Policy¶
Failed deliveries are automatically retried:
- Immediate retry
- 2 seconds delay
- 4 seconds delay
- 8 seconds delay
- 16 seconds delay
Best Practices¶
- Return 200-299 for successful processing
- Verify signatures for security
- Implement idempotency for duplicate handling
- Process quickly to avoid timeouts
- Monitor delivery status