Webhooks

Set up webhook alerts for quota thresholds

Configure webhooks to receive real-time notifications when quotas are exceeded or thresholds are crossed.

Creating a Webhook Alert

const alert = await client.quotaAlerts.create({
  quotaId: 'quota_123',
  threshold: 80, // Alert at 80% of quota
  webhookUrl: 'https://your-app.com/webhooks/quota-alert',
});
alert = await client.quota_alerts.create(
    quota_id="quota_123",
    threshold=80,  # Alert at 80% of quota
    webhook_url="https://your-app.com/webhooks/quota-alert",
)

Handling Webhook Events

Your webhook endpoint should handle quota alert events.

// Example webhook handler
app.post('/webhooks/quota-alert', async (req, res) => {
  const { event, quota, customerId, usage } = req.body;
  
  if (event === 'quota.threshold_exceeded') {
    // Send notification to customer
    await notifyCustomer(customerId, quota, usage);
  }
  
  res.status(200).send('OK');
});

Next Steps

On this page