# Create a webhook (old)

> Create a webhook (old): POST /webhooks.

**POST** `/webhooks` **Old: still works, use the newer one**

Replaced by POST /webhook_endpoints. Still answers its old shape, with a Deprecation header. The secret is in this reply only. Needs the read permission of every event's data, as POST /webhook_endpoints does.

## Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string |  | Any string you choose (1 to 255 visible characters), new for each new action. Send the same key again within 24 hours and you get the first answer back instead of a second lead or call. At most 255 characters. |

## Body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `url` | string | yes |  |
| `events` | array of string | yes |  |
| `campaignId` | string (uuid) or null |  |  |
| `enabled` | boolean |  | Default `true`. |

## Example request

### curl

```bash
curl -X POST 'https://v2-api.callview.ai/api/v1/external/webhooks' \
  -u "$CALLVIEW_KEY_ID:$CALLVIEW_SECRET" \
  -H 'Idempotency-Key: postWebhooks-0001' \
  -H 'Content-Type: application/json' \
  -d '{
  "url": "https://crm.example.com/callview",
  "events": [
    "string"
  ],
  "campaignId": "e4d3c2b1-a09f-4e8d-9c7b-6a5f4e3d2c1b",
  "enabled": true
}'
```

### Node

```js
import { randomUUID } from 'node:crypto';

const auth = Buffer.from(`${process.env.CALLVIEW_KEY_ID}:${process.env.CALLVIEW_SECRET}`).toString('base64');

const res = await fetch('https://v2-api.callview.ai/api/v1/external/webhooks', {
  method: 'POST',
  headers: { Authorization: `Basic ${auth}`, 'Content-Type': 'application/json', 'Idempotency-Key': randomUUID() },
  body: JSON.stringify({
    "url": "https://crm.example.com/callview",
    "events": [
      "string"
    ],
    "campaignId": "e4d3c2b1-a09f-4e8d-9c7b-6a5f4e3d2c1b",
    "enabled": true
  }),
});
console.log(res.status, res.headers.get('request-id'));
console.log(await res.text());
```

### Python

```python
import os, uuid

import requests

res = requests.request(
    "POST",
    "https://v2-api.callview.ai/api/v1/external/webhooks",
    auth=(os.environ["CALLVIEW_KEY_ID"], os.environ["CALLVIEW_SECRET"]),
    headers={"Idempotency-Key": str(uuid.uuid4())},
    json={
        "url": "https://crm.example.com/callview",
        "events": [
            "string",
        ],
        "campaignId": "e4d3c2b1-a09f-4e8d-9c7b-6a5f4e3d2c1b",
        "enabled": True,
    },
    timeout=30,
)
print(res.status_code, res.headers.get("Request-Id"))
print(res.text)
```

### PHP

```php
<?php
$ch = curl_init('https://v2-api.callview.ai/api/v1/external/webhooks');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_USERPWD => getenv('CALLVIEW_KEY_ID') . ':' . getenv('CALLVIEW_SECRET'),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Idempotency-Key: ' . bin2hex(random_bytes(16))],
    CURLOPT_POSTFIELDS => <<<'JSON'
{
  "url": "https://crm.example.com/callview",
  "events": [
    "string"
  ],
  "campaignId": "e4d3c2b1-a09f-4e8d-9c7b-6a5f4e3d2c1b",
  "enabled": true
}
JSON,
    CURLOPT_HEADER => false,
]);
$body = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), "\n", $body, "\n";
```

## Response

**201** Created

```json
{}
```

## Errors

| Status | Codes |
| --- | --- |
| 400 | [`invalid_request`](https://developers.callview.ai/reference/errors/#invalid_request) |
| 401 | [`authentication_failed`](https://developers.callview.ai/reference/errors/#authentication_failed) |
| 403 | [`permission_denied`](https://developers.callview.ai/reference/errors/#permission_denied), [`limit_reached`](https://developers.callview.ai/reference/errors/#limit_reached) |
| 409 | [`idempotency_mismatch`](https://developers.callview.ai/reference/errors/#idempotency_mismatch), [`idempotency_in_progress`](https://developers.callview.ai/reference/errors/#idempotency_in_progress) |
| 429 | [`rate_limited`](https://developers.callview.ai/reference/errors/#rate_limited), [`too_many_concurrent_requests`](https://developers.callview.ai/reference/errors/#too_many_concurrent_requests) |
| 500 | [`internal_error`](https://developers.callview.ai/reference/errors/#internal_error) |
| 503 | [`service_unavailable`](https://developers.callview.ai/reference/errors/#service_unavailable) |

Part of [Webhook endpoints](https://developers.callview.ai/reference/webhook-endpoints/). Every example sends your key ID and secret as `CALLVIEW_KEY_ID` and `CALLVIEW_SECRET` (see [Keys and authentication](https://developers.callview.ai/guides/authentication/)).
