Skip to main content

Overview

Protocol: HTTPS POST callbacks Pattern: Event-driven (Server → Client) Direction: Unidirectional (Server calls your endpoint) When to Use Webhooks:
  • ✅ Real-time event notifications
  • ✅ Order status updates
  • ✅ Payment confirmations
  • ✅ Pet adoption notifications
  • ✅ Inventory alerts
When NOT to Use Webhooks:
  • ❌ You need to request data (use REST instead)
  • ❌ Your endpoint is not publicly accessible (use polling instead)

How Webhooks Work

Key Characteristics:
  • Server initiates the request
  • Push-based (no polling needed)
  • Event-driven architecture
  • HMAC signature verification
  • Automatic retry on failure

Webhook Events

Pet Events

Pet Adopted

Pet Status Changed

Order Events

Order Created

Order Status Changed

Payment Events

Payment Succeeded

Payment Failed


Setting Up Webhooks

1. Register Your Webhook URL

Response:

2. Create Webhook Endpoint

3. Test Your Webhook


Signature Verification

Why Verify Signatures?

  • ✅ Ensure webhook is from Petstore API
  • ✅ Detect tampering
  • ✅ Prevent fraud

Verification Process


Best Practices

1. Always Return 200 OK Quickly

2. Handle Duplicate Events

3. Retry Logic

The API will retry webhooks that fail: After 5 failed attempts, the webhook is disabled.

4. Idempotency

Make your webhook handlers idempotent:

Security

1. Use HTTPS

Always use HTTPS for your webhook endpoint.

2. Verify Signatures

Never process webhook events without signature verification.

3. Validate Payloads

4. Rate Limiting


Managing Webhooks

List Webhooks

Get Webhook Details

Update Webhook

Delete Webhook


Troubleshooting

Not Receiving Webhooks

  1. Check webhook status is active
  2. Verify endpoint URL is publicly accessible
  3. Confirm HTTPS certificate is valid
  4. Check server logs for connection attempts
  5. Test with webhook test endpoint

Signature Verification Fails

  • Ensure you’re using the correct secret
  • Verify you’re comparing the entire signature
  • Check for encoding issues

High Failure Rate

  • Ensure endpoint responds quickly (< 5 seconds)
  • Always return 200 OK (even if processing fails later)
  • Implement retry logic in your application
  • Monitor endpoint uptime

Comparison with Alternatives


Interactive Documentation