# Create webhook

> Source: https://truto.one/docs/api-reference/admin/webhooks/create/

`POST /webhook`

Resource: **Webhooks**

## Request body

- **`target_url`** _(string)_
  The URL where the webhook payload will be sent.
- **`is_active`** _(boolean)_
  Whether the webhook is active or not.
- **`event_types`** _(array<string>)_
  The list of event types that the webhook is subscribed to. If not specified, then the webhook will be subscribed to all event types.

## Response body

- **`id`** _(string)_
  The ID of the webhook.
- **`target_url`** _(string)_
  The URL where the webhook should send the data.
- **`is_active`** _(boolean)_
  Whether the webhook is active or not. Inactive webhooks will not receive any data.
- **`environment_id`** _(string)_
  The ID of the environment that this webhook belongs to.
- **`event_types`** _(array<string>)_
  The list of event types that the webhook is subscribed to.
- **`created_at`** _(string)_
  The date and time when the webhook was created.
- **`updated_at`** _(string)_
  The date and time when the webhook was last updated.
- **`secret`** _(string)_
  The secret key that will be used to sign the webhook payload.

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/webhook' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "target_url": "https://example.com/webhook",
  "is_active": true,
  "event_types": []
}'
```

### JavaScript

```javascript
const body = {
  "target_url": "https://example.com/webhook",
  "is_active": true,
  "event_types": []
};

const response = await fetch('https://api.truto.one/webhook', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/webhook"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "target_url": "https://example.com/webhook",
    "is_active": True,
    "event_types": []
}

response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())
```

### Truto TS SDK

```typescript
import Truto from '@truto/truto-ts-sdk';

const truto = new Truto({
  token: '<your_api_token>',
});

const body = {
  "target_url": "https://example.com/webhook",
  "is_active": true,
  "event_types": []
};

const result = await truto.webhook.create(body);

console.log(result);
```

### Truto Python SDK

```python
import asyncio
from truto_python_sdk import TrutoApi

truto_api = TrutoApi(token="<your_api_token>")

async def main():
    body = {
        "target_url": "https://example.com/webhook",
        "is_active": True,
        "event_types": []
    }

    result = await truto_api.webhooks.create(body)
    print(result)

asyncio.run(main())
```
