# Webhooks

This capability allows you to create webhooks which will notify a given URL whenever an action happens in Peek Pro, e.g. Booking Update or Booking Cancellation.

## Create Webhook

<mark style="color:green;">`POST`</mark> `https://octo.peek.com/integrations/octo/webhooks`

Create a new webhook

#### Request Body

| Name                                    | Type   | Description                                   |
| --------------------------------------- | ------ | --------------------------------------------- |
| url<mark style="color:red;">\*</mark>   | String | The URL to call when the webhook is triggered |
| event<mark style="color:red;">\*</mark> | String | The event that will trigger the webhook       |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
  "id": "octohook_123",
  "event": "booking_update",
  "url": "https://example.com/webhooks/availability_update"
}
```

{% endtab %}
{% endtabs %}

| Field   | Description                                                                                                                                                                                                                                     |
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`   | <p>A fully formed URL. If you want to include basic authentication credentials that is supported also. For example:</p><ul><li><code><https://user:pass@example.com/webook></code></li><li><code><https://example.com/webhook></code></li></ul> |
| `event` | <p>The event that will trigger the webhook. Possible values are:</p><p><code>booking\_update</code> triggered when an existing booking is confirmed, updated or cancelled.</p>                                                                  |

An example response will look like this:

```javascript
{
  "id": "octohook_123",
  "event": "booking_update",
  "url": "https://example.com/webhooks/booking_update"
}
```

We recommend for testing you can use [ngrok](https://ngrok.com/) to create an endpoint which connects to your localhost. You can then make test bookings with the same credentials and see the webhook requests arrive.

When an event is triggered the webhook will perform a `POST` HTTP request to the specified URL, the request body will look like this depending on the event type:

{% tabs %}
{% tab title="booking\_update" %}

```javascript
{
  "webhook": {
    "id": "octohook_123",
    "event": "booking_update",
    "url": "https://example.com/webhooks/booking_update"
  },
  "booking": {
    "uuid": "89fe0192-ddcd-430a-b285-e1396a4725d2",
    "testMode": true,
    "resellerReference": null,
    "supplierReference": "X749G9",
    "status": "ON_HOLD",
    "utcExpiresAt": "2020-06-07T17:06:37Z",
    "utcConfirmedAt": null,
    "productId": "av_123",
    "optionId": "av_123",
    "cancellable": true,
    "cancellation": null,
    "freesale": false,
    "notes": "optional notes on the booking",
    "availability": {
      "id": "20200701143000_720_5214a9d6-5271-4958-a306-14a07e4084c6",
      "localDateTimeStart": "2020-07-01T14:30:00-08:00",
      "localDateTimeEnd": "2020-07-02T02:30:00-08:00",
      "allDay": true,
      "openingHours": []
    },
    "contact": {
      "fullName": null,
      "emailAddress": null,
      "phoneNumber": null,
      "locales": [],
      "country": null
    },
    "deliveryMethods": [
      "VOUCHER"
    ],
    "voucher": {
      "redemptionMethod": "DIGITAL",
      "utcRedeemedAt": null,
      "deliveryOptions": []
    },
    "unitItems": [
      {
        "uuid": "eeddd74e-88e6-4dab-84e9-14f7af18935f",
        "resellerReference": null,
        "supplierReference": "408H44",
        "unitId": "ecbdb23e-9840-4d15-b6f4-254a9ea401b2"
      },
      {
        "uuid": "ec1e2622-1359-437b-83f8-15182759d605",
        "resellerReference": null,
        "supplierReference": "BSDYM4",
        "unitId": "ecbdb23e-9840-4d15-b6f4-254a9ea401b2"
      },
      {
        "uuid": "de9855fd-8176-4551-9ba9-ae8c997cb2bb",
        "resellerReference": null,
        "supplierReference": "E5K92G",
        "unitId": "480d0c3e-80a1-4bf2-a39b-aa06332739df"
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}

This endpoint will return a list of all existing webhooks.

## List Webhooks

<mark style="color:blue;">`GET`</mark> `https://octo.peek.com/integrations/octo/webhooks`

List all webhooks

{% tabs %}
{% tab title="200: OK " %}

```javascript
[
  {
    "id": "octohook_123",
    "event": "booking_update",
    "url": "https://example.com/webhooks/booking_update"
  }
]
```

{% endtab %}
{% endtabs %}

## Delete Webhooks

<mark style="color:red;">`DELETE`</mark> `https://octo.peek.com/integrations/octo/webhooks/:id`

Delete an existing webhook

#### Path Parameters

| Name                                 | Type   | Description    |
| ------------------------------------ | ------ | -------------- |
| id<mark style="color:red;">\*</mark> | String | The webhook id |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
  "id": "octohook_123",
  "event": "booking_update",
  "url": "https://example.com/webhooks/booking_update"
  }
]
```

{% endtab %}
{% endtabs %}
