AMS Docs

Webhooks

Webhooks allow AMS to push real-time notifications to your systems whenever specific events occur in the platform. Instead of polling the API, your endpoint receives an HTTP POST request the moment something happens — a new member joins, a payment is received, or a job is applied for.

Setting Up a Webhook

Create a webhook subscription by POSTing to the webhooks endpoint with your target URL and the list of events you want to subscribe to:

bash — create webhook
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/webhooks \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://yourapp.example.com/webhooks/ams",
    "events": ["member.created", "payment.received", "event.created"],
    "secret": "your-webhook-signing-secret",
    "active": true,
    "description": "Main app webhook"
  }'

Supported Events

EventTrigger
member.createdA new member profile is created
member.updatedA member's profile data is changed
member.deletedA member is deleted or deactivated
event.createdA new event is published
event.updatedEvent details are modified
event.cancelledAn event is cancelled
registration.createdA member registers for an event
registration.cancelledA registration is cancelled
payment.receivedA payment is successfully processed
payment.failedA payment attempt fails
job.postedA new job listing is published
job.appliedA member applies for a job

Webhook Payload Structure

All webhook deliveries share the same envelope structure regardless of event type:

json — webhook payload
{
  "id": "whe_01HXYZ",
  "event": "member.created",
  "created_at": "2026-03-14T10:23:45Z",
  "tenant_id": "ten_pasha",
  "data": {
    "id": "mem_01HABC",
    "first_name": "Sarah",
    "last_name": "Ahmed",
    "email": "sarah.ahmed@example.com",
    "membership_type": "full",
    "status": "active",
    "joined_at": "2026-03-14T10:23:44Z"
  }
}

Signature Verification

Every webhook delivery includes an X-AMS-Signature header containing an HMAC-SHA256 signature of the raw request body, signed with your webhook secret. Always verify this signature before processing the payload to ensure the request is genuine.

php — verify signature
function verifyWebhook(string $payload, string $secret, string $header): bool
{
    $signature = hash_hmac('sha256', $payload, $secret);
    $expected = 'sha256=' . $signature;
    return hash_equals($expected, $header);
}

// Usage in Laravel controller
$payload = $request->getContent();
$secret = config('services.ams.webhook_secret');
$header = $request->header('X-AMS-Signature');

if (!verifyWebhook($payload, $secret, $header)) {
    return response('Unauthorized', 401);
}
javascript (node.js) — verify signature
const crypto = require('crypto');

function verifyWebhook(payload, secret, header) {
  const signature = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(header)
  );
}

Retry Logic

AMS considers a webhook delivery successful if your endpoint returns an HTTP 2xx status code within 10 seconds. If the delivery fails, AMS will retry up to 3 times using exponential backoff:

AttemptDelay After Failure
1st retry5 minutes
2nd retry30 minutes
3rd retry2 hours

After 3 failed retries, the webhook delivery is marked as failed. You can manually re-trigger failed deliveries from the webhook logs page or via the API.

⚠️ Respond QuicklyYour webhook endpoint must respond within 10 seconds. For time-consuming operations, immediately return 200 and process the payload asynchronously in a background job.

Webhook Logs

View delivery history for a webhook subscription:

bash — get webhook logs
curl -X GET https://yourdomain.ams.hkus1.s4s.host/api/v1/webhooks/wh_01HXYZ/logs \
  -H "Authorization: Bearer $TOKEN"

Testing Webhooks

Send a test payload to your webhook endpoint without triggering a real event:

bash — send test payload
curl -X POST https://yourdomain.ams.hkus1.s4s.host/api/v1/webhooks/wh_01HXYZ/test \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"event": "member.created"}'

Local Development with ngrok

To receive webhooks during local development, use ngrok to expose your local server to the internet:

bash — ngrok setup
# Install ngrok, then start a tunnel on your local port
ngrok http 3000

# ngrok will output a public URL like:
# https://abc123.ngrok-free.app

# Use this URL when creating your webhook
# "url": "https://abc123.ngrok-free.app/webhooks/ams"