Webhook and API Key Setup

Efficiently set up webhooks and API keys with concise instructions.

Create Webhook and API Key

Use the combined endpoint to create both a webhook and its API key in one request

async function createWebhookAndApiKey() {
  const response = await fetch('https://backend.sa.amwal.tech/api/create-webhook-and-apikey/', {
    method: 'POST',
    headers: {
      'Authorization': 'YOUR_MERCHANT_SECRET_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://your-domain.com/webhooks/amwal',
      description: 'Production webhook for order events',
      event_type_names: ['order.created', 'order.success', 'order.failed'],
      api_key_name: 'Production Webhook Key',
      api_key_scopes: ['trigger_events', 'manage_webhooks']
    })
  });

  const data = await response.json();
  console.log('Webhook created:', data);
  console.warn('⚠️ Store this public key securely - it will not be shown again!');
  console.log('Public Key:', data.api_key.public_key);
  return data;
}

createWebhookAndApiKey();

Response:

{
  "webhook": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "url": "https://your-domain.com/webhooks/amwal",
    "description": "Production webhook for order events"
  },
  "api_key": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Production Webhook Key",
    "fingerprint": "8a7d42f1c4e6ba957beec92f2cad51d0b3ec4f8c9a1529e8f35e53a1de1a8b3b",
    "public_key": "-----BEGIN PUBLIC KEY-----\nMIIEvgIBADANBgkqhkiG9w0B...",
    "message": "Store this public key securely. It won't be shown again."
  }
}
⚠️

Important

Store the public key securely immediately.