# Create a Subscription Bot Webhook

> Register an HTTPS webhook receiver for your Telegram or Discord subscription bot project and capture its signing secret.

Source: https://docs.botsubscription.com/api/integrations/create-webhook/

Register a new endpoint to receive real-time event notifications from your subscription bot. When payments complete, memberships change, or other events occur, BotSubscription sends HTTP POST requests to your specified URL with event details and a signature for verification.

<ApiEndpoint method="POST" endpoint="/v2/projects/{project_id}/integrations/webhooks" />

<ApiAuthorization type="Bearer API Key" />

**API key access:** Use an unrestricted project API key for payment, membership, and subscription event feeds. Restricted project keys cannot create these feeds; `webhooks:create` alone does not grant project-wide event access. A request with no readable events returns `401 UNAUTHORIZED`.

Each project is capped at **10 webhook endpoints**; the endpoint returns `409` when that limit is reached, and also rejects a second endpoint that reuses an existing URL with `409`. The `secret` is returned only on creation—store it immediately to verify incoming signatures.

**Retries:** save the first successful response. A completed request made with `Idempotency-Key` cannot replay its signing secret and returns `409 IDEMPOTENCY_RESPONSE_NOT_REPLAYABLE`. Reconcile registration state before starting another creation attempt.

Register endpoints with HTTPS, including during development. Localhost, loopback, private and reserved addresses are blocked, including hostnames resolving to them. See [webhook receiver requirements](https://docs.botsubscription.com/webhooks/overview/#registering-webhook-endpoints).

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="url" type="string" required description="The final, publicly reachable HTTPS URL for webhook events. Redirects are not followed." />
  <ApiParameter name="events" type="string[]" description="Optional 1–64 exact event names or family selectors. For example payment-request.completed or subscription.*. Omit to subscribe to every event family available to the key." />
</ApiSection>

## Choose subscription bot events

Use exact names to receive a single event, such as `payment-request.completed` or `subscription.renewal-held`. Family selectors `payment-request.*`, `membership.*`, and `subscription.*` include their registered events. Duplicate selectors are removed before saving.

Unknown selectors and an empty array return `422 VALIDATION_ERROR`. Selecting events unavailable to the creator returns `401 UNAUTHORIZED` and creates nothing. `webhook.test` is a diagnostic event and cannot be selected.

The creator's event access is captured when registering the endpoint. Later permission changes do not stop the feed; delete the endpoint to stop delivery. Previously registered HTTP URLs no longer receive events. Delete them and register the final HTTPS address.

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X POST "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/integrations/webhooks" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://myapp.com/webhooks/botsubscription",
    "events": ["payment-request.completed", "subscription.renewal-held"]
  }'
```

```javascript
const project_id = 'YOUR_PROJECT_ID';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/integrations/webhooks`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://myapp.com/webhooks/botsubscription',
    events: ['payment-request.completed', 'subscription.renewal-held']
  })
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'
response = requests.post(
    f'https://api.botsubscription.com/v2/projects/{project_id}/integrations/webhooks',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={'url': 'https://myapp.com/webhooks/botsubscription',
          'events': ['payment-request.completed', 'subscription.renewal-held']}
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/integrations/webhooks");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'url' => 'https://myapp.com/webhooks/botsubscription',
    'events' => ['payment-request.completed', 'subscription.renewal-held']
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={200} description="Webhook created">

```json
{
  "ok": true,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/integrations/webhooks",
  "code": 200,
  "message": "Webhook created successfully",
  "data": {
    "id": "22222222-2222-4222-8222-222222222222",
    "url": "https://myapp.com/webhooks/botsubscription",
    "secret": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "events": [
      "payment-request.completed",
      "subscription.renewal-held"
    ]
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Invalid webhook URL">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/integrations/webhooks",
  "code": 422,
  "errors": [
    {
      "message": "body: url Invalid webhook URL",
      "error_code": "VALIDATION_ERROR"
    },
    {
      "message": "body: url Invalid URL format",
      "error_code": "VALIDATION_ERROR"
    }
  ]
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Webhook URL already registered">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/integrations/webhooks",
  "code": 409,
  "error": {
    "error_code": "CONFLICT",
    "message": "Webhook URL already exists"
  }
}
```

  </ApiResponse>
  <ApiResponse status={409} description="Completed secret response cannot be replayed">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/integrations/webhooks",
  "code": 409,
  "error": {
    "error_code": "IDEMPOTENCY_RESPONSE_NOT_REPLAYABLE",
    "message": "A request with this Idempotency-Key was already processed, but its response cannot be replayed"
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/integrations/webhooks",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
