# Create Webhooks

You can use webhooks for 2-way syncing of calendar events. All you need to do is provide Pyas with a webhook URL and select the events you would like to receive notifications for.

**Note**: Using webhooks for 2-way syncing is only supported for Google and Microsoft at this time.&#x20;

### How it Works

1. You provide a webhook URL.
2. You choose which triggers/notifications you want to receive from Pyas.
3. Pyas sends the notifications in a <mark style="color:green;">**POST**</mark> request to the webhook URL that you provided.
4. You receive and handle the notifications on your end.

### Pyas will send notifications for the following triggers:

1. **Accounts** - these are for your users' *connected* accounts in Pyas.
   * <mark style="color:green;">`account.connected`</mark>
   * <mark style="color:orange;">`account.inactive`</mark>
   * <mark style="color:red;">`account.deleted`</mark>
2. **Calendars** - these triggers currently work for Google only.
   * <mark style="color:green;">`calendars.created`</mark>
   * <mark style="color:red;">`calendars.deleted`</mark>
3. **Calendar Events** - these triggers work for Google and Microsoft.
   * <mark style="color:green;">`events.created`</mark>
   * <mark style="color:purple;">`events.updated`</mark>
   * <mark style="color:red;">`events.deleted`</mark>

## The Webhook Request

### Method

<mark style="color:green;">POST</mark>

### Headers

Each request has the following headers:

```typescript
'x-pyas-account-id': string. // The id of the connected account in Pyas
'x-pyas-webhook-event': string. // The event trigger
'x-provider': string. // The connected account's provider. (Google, Microsoft, or Zoom)
```

### **Body**

The request body for **Calendar Events** notifications will have an events array and looks like this:

```typescript
{
    "events": [
        {
            "calendarId": string. // The calendar id
            "eventId": string. // The event id
        }
    ]
}
```

The request body for **Calendar** notifications will have an array of calendar ids and looks like this:

```typescript
{
    "calendarIds": [ // calendar id strings ]
}
```

The request body for **Account** notifications is empty.

## Create a new Webhook

1. Login to your Pyas account and click on the **Apps** tab on the left menu.
2. Select the app that you want to set the webhook for.
3. From the app screen, click on the **Webhooks** tab.
4. Click on the **Create Webhook** button.
5. Add your webhook URL. This is a URL that should be setup on your server to receive the webhook notifications from Pyas.
6. Select the triggers that you want. These are events/notifications that Pyas will send to your server.
7. **Click the Create** button.

<figure><img src="https://703485338-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzAOD4a5iAUra2DB1y99h%2Fuploads%2F7xfpuiJsQ4QnrTPYGkyB%2Fpyas-app-screen.PNG?alt=media&#x26;token=c27ae6d1-3c13-4802-ae0f-7f2eaa0b70a1" alt=""><figcaption></figcaption></figure>

<figure><img src="https://703485338-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzAOD4a5iAUra2DB1y99h%2Fuploads%2Fa1P0v1ooc5guFQmCYnXi%2Fpyas-webhook-create.PNG?alt=media&#x26;token=ab717d25-4640-4519-ba7e-f9dbf2934c01" alt=""><figcaption></figcaption></figure>

### That's it!
