> ## Documentation Index
> Fetch the complete documentation index at: https://developers.fibery.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Use webhooks to update other tools based on changes in Fibery.

There are two ways to manage webhooks:

1. Navigate to `Settings → Webhooks` page and see, add or delete webhooks there.
2. Use `/api/webhooks/v2` endpoint to add or delete a webhook.

<Callout icon="lock" color="#9c2baf">
  Managing webhooks requires `Architect` access to either Space or Database.
</Callout>

## Add webhook

Add a webhook to subscribe to Entity changes of a particular [Database](/guides/http-api/databases).

When one **or several** changes occur, Fibery sends a JSON with new and previous values to the specified URL. To add a new webhook, navigate to `Settings → Webhooks` and click **Add Webhook** button.

<img src="https://mintcdn.com/fibery/RPlQYSukIff8siBE/images/595053ad-cf47-4bd8-bfbf-7009fd20e8e1.png?fit=max&auto=format&n=RPlQYSukIff8siBE&q=85&s=8ad04805aa238f1ddc3d03abdb885797" alt="Webhooks settings page" width="2534" height="1358" data-path="images/595053ad-cf47-4bd8-bfbf-7009fd20e8e1.png" />

Filter and process the payload in your integration. If you need some extra fields, send a request to the regular API (check [Select Fields](/guides/http-api/query-entities#select-fields) for more).

<Callout icon="circle-exclamation" color="#1fbed3">
  Please note that you can send correlationId, as shown in API call example, to match it with webhook call.\
  Then you will receive the same correlationId in corresponding webhook event.
</Callout>

Limitations:

<Callout icon="circle-exclamation" color="#fba32f">
  Webhooks do not support rich text Field changes at the moment.
</Callout>

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'http://webhook.site/c2d6d113-aebe-4f68-a337-022ec3c7ab5d',
      type: 'Cricket/Player'
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2 \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d \
    '{
      "url": "http://webhook.site/c2d6d113-aebe-4f68-a337-022ec3c7ab5d",
      "type": "Cricket/Player"
    }'
  ```
</CodeGroup>

Result:

```json theme={null}
{
  "id": 5,
  "url": "http://webhook.site/c2d6d113-aebe-4f68-a337-022ec3c7ab5d",
  "type": "Cricket/Player",
  "state": "active",
  "version": "2",
  "runs": []
}
```

Once you update a couple of Fields:

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify([
      {
        command: 'fibery.command/batch',
        correlationId: 'cd4490f1-21d8-4881-b85c-423ef98edc3d',
        args: {
          commands: [
            {
              command: 'fibery.entity/update',
              args: {
                type: 'Cricket/Player',
                entity: {
                  'fibery/id': 'd17390c4-98c8-11e9-a2a3-2a2ae2dbcce4',
                  'fibery/modification-date': '2019-07-30T07:18:48.449Z',
                  'Cricket/name': 'sir Curtly Ambrose'
                }
              }
            },
            {
              command: 'fibery.entity/add-collection-items',
              args: {
                type: 'Cricket/Player',
                field: 'user/Former~Teams',
                entity: { 'fibery/id': 'd17390c4-98c8-11e9-a2a3-2a2ae2dbcce4' },
                items: [
                  { 'fibery/id': 'd328b7b0-97fa-11e9-81b9-4363f716f666' }
                ]
              }
            }
          ]
        }
      }
    ])
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d \
    '[
      {
        "command": "fibery.command/batch",
        "correlationId": "cd4490f1-21d8-4881-b85c-423ef98edc3d",
        "args": {
          "commands": [
            {
              "command": "fibery.entity/update",
              "args": {
                "type": "Cricket/Player",
                "entity": {
                  "fibery/id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4",
                  "fibery/modification-date": "2019-07-30T07:18:48.449Z",
                  "Cricket/name": "sir Curtly Ambrose"
                }
              }
            },
            {
              "command": "fibery.entity/add-collection-items",
              "args": {
                "type": "Cricket/Player",
                "field": "user/Former~Teams",
                "entity": {"fibery/id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4"},
                "items": [
                  {"fibery/id": "d328b7b0-97fa-11e9-81b9-4363f716f666"}
                ]
              }
            }
          ]
        }
      }
    ]'
  ```
</CodeGroup>

the endpoint receives an array of effects:

```json theme={null}
{
  "sequenceId":392,
  "authorId":"4044090b-7165-4791-ac15-20fb12ae0b64",
  "creationDate":"2021-04-22T12:40:14.325Z",
  "command": {
    "correlationId": "cd4490f1-21d8-4881-b85c-423ef98edc3d"
  },
  "effects":
  [
    {
      "effect": "fibery.entity/update",
      "id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4",
      "type": "Cricket/Player",
      "values": {
        "fibery/modification-date": "2019-07-30T07:18:48.449Z",
        "Cricket/name": "sir Curtly Ambrose"
      },
      "valuesBefore": {
        "fibery/modification-date": "2019-07-04T11:12:13.423Z",
        "Cricket/name": "Curtly Ambrose"
      }
    },
    {
      "effect": "fibery.entity/add-collection-items",
      "id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4",
      "type": "Cricket/Player",
      "field": "user/Former~Teams",
      "items": [
        {
          "fibery/id": "d328b7b0-97fa-11e9-81b9-4363f716f666"
        }
      ]
    }
  ],
}
```

## Delete webhook

Delete a webhook when you no longer need it to save the account resources.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2/WEBHOOK_ID', {
    method: 'DELETE',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    }
  });
  ```

  ```bash cURL theme={null}
  curl -X DELETE https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2/WEBHOOK_ID \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json'
  ```
</CodeGroup>

Status code 200 means that the deletion has been successful.

## Get webhooks

Get a list of webhooks together with their latest 50 runs.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2', {
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    }
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X GET https://YOUR_ACCOUNT.fibery.io/api/webhooks/v2 \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json'
  ```
</CodeGroup>

Result:

```json theme={null}
[
  {
    "id": 5,
    "url": "http://webhook.site/c2d6d113-aebe-4f68-a337-022ec3c7ab5d",
    "type": "Cricket/Player",
    "state": "active",
    "runs": [
      {
        "http_status": "200",
        "elapsed_time": "209",
        "request_time": "2019-07-30T07:18:49.883Z"
      },
      {
        "http_status": "200",
        "elapsed_time": "181",
        "request_time": "2019-07-30T07:23:06.738Z"
      }
    ]
  }
]
```
