# Create a webhook

Source: https://developers.swell.is/backend-api/webhooks/create-a-webhook

When setting up webhooks for custom models, you will need to create them via the API referencing the events listed on the custom model. For webhooks that utilize Swell's standard models, we recommend configuration through the Swell dashboard under **Developer tools > Webhooks**—each standard model's events are easily referenced within the UI.

## Arguments

- `url` (string, required): URL endpoint for the webhook.
- `events` (array of string, required): Array of trigger events for the webhook.
- `id` (objectId, auto): The unique identifier for the webhook.
- `alias` (string): Alias used to refer to the webhook configuration.
- `api` (string, required): API the webhook subscribes to—`com` for the store API.
- `enabled` (boolean): Determines whether the webhook is enabled. Defaults to `false`. Default: `false`.
- `auto_disabled` (boolean, auto): Indicates whether the webhook was automatically disabled. This occurs when the webhook has failed for 4 days with no successful delivery in that time.
- `retry_disabled_events` (boolean): Determines whether the webhook retries disabled events.
- `attempts_failed` (int): The number of failed webhook attempts.
- `date_first_failed` (date, auto): The date of the webhook's first failed attempt.
- `date_last_success` (date): Date of the last successful webhook delivery.
- `date_last_warned` (date, auto): The date of the last warning for a failed attempt.
- `date_final_attempt` (date): The final attempt for a webhook after continuous failed attempts. Webhooks are disabled after failing for 4 days with no successful delivery.

## Example request

`POST /:webhooks`

**cURL**

```bash
$ curl https://api.swell.store/:webhooks \
  -u store-id:secret-key \
  -d url=http://localhost:5000 \
  -d "events[0]=order.created" \
  -d "events[1]=order.submitted"
```

**Node**

```javascript
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');

await swell.post('/:webhooks', {
  url: 'http://localhost:5000',
  events: [
    'order.created',
    'order.submitted'
  ]
});
```

**PHP**

```php
<?php $swell = new \Swell\Client('store-id', 'secret-key');

$swell->post('/:webhooks', [
  'url' => 'http://localhost:5000',
  'events' => ['order.created', 'order.submitted']
]);
```

## Example response

```json
{
  "url": "http://localhost:5000",
  "enabled": false,
  "alias": "webhook",
  "description": null,
  "events": [
    "order.created",
    "order.submitted",
    "order.updated"
  ],
  "api": "com",
  "date_final_attempt": null,
  "date_scheduled": null,
  "date_created": "2021-09-27T16:30:11.837Z",
  "date_updated": "2021-10-28T16:04:21.648Z",
  "id": "6151f193ae97e82ccbf6f0a7"
}
```
