> ## Documentation Index
> Fetch the complete documentation index at: https://usegately.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks Overview

> Set up webhooks to receive real-time event notifications

Webhooks allow your application to receive real-time notifications when events occur in your Gately project.

## How Webhooks Work

1. You register a webhook endpoint URL
2. When an event occurs, Gately sends an HTTP POST request to your URL
3. Your server processes the event and returns a 200 response

## Creating a Webhook

### Via Dashboard

1. Navigate to **Webhooks** in your dashboard
2. Click **Create Webhook**
3. Enter your endpoint URL
4. Select the events you want to receive
5. Click **Create**

### Via API

```bash theme={null}
curl -X POST "https://api.usegately.com/api/v1/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-server.com/webhooks/gately",
    "events": ["member.created", "member.updated", "form.submitted"],
    "active": true
  }'
```

## Webhook Payload

All webhook payloads include:

```json theme={null}
{
  "id": "evt_abc123",
  "event": "member.created",
  "created_at": "2024-01-15T10:00:00Z",
  "project_id": "proj_xyz789",
  "data": {
    // Event-specific data
  }
}
```

## Security

### Signature Verification

All webhooks include a signature header for verification:

```
X-Gately-Signature: sha256=abc123def456...
```

Verify the signature to ensure the request is from Gately:

```javascript theme={null}
const crypto = require('crypto')

function verifySignature(payload, signature, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(payload, 'utf8')
    .digest('hex')
  
  return signature === `sha256=${expected}`
}
```

### Best Practices

* Always verify webhook signatures
* Use HTTPS endpoints only
* Respond quickly (within 30 seconds)
* Process events asynchronously
* Handle duplicate events idempotently

## Retry Policy

Failed webhook deliveries are retried with exponential backoff:

| Attempt | Delay      |
| ------- | ---------- |
| 1       | Immediate  |
| 2       | 1 minute   |
| 3       | 5 minutes  |
| 4       | 30 minutes |
| 5       | 2 hours    |

After 5 failed attempts, the webhook delivery is marked as failed.

## Managing Webhooks

### List Webhooks

```bash theme={null}
curl -X GET "https://api.usegately.com/api/v1/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

### Update Webhook

```bash theme={null}
curl -X PUT "https://api.usegately.com/api/v1/webhooks/{webhook_id}" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": ["member.created"],
    "active": false
  }'
```

### Delete Webhook

```bash theme={null}
curl -X DELETE "https://api.usegately.com/api/v1/webhooks/{webhook_id}" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Testing

### Send Test Event

```bash theme={null}
curl -X POST "https://api.usegately.com/api/v1/webhooks/{webhook_id}/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "member.created"
  }'
```

### View Delivery Logs

```bash theme={null}
curl -X GET "https://api.usegately.com/api/v1/webhooks/{webhook_id}/logs" \
  -H "Authorization: Bearer YOUR_API_KEY"
```
