<!-- Generated from the canonical 99 Digital API documentation. Do not edit this file. -->

Canonical page: https://docs.99digital.co.il/facebook-api/webhooks/set-webhook

# Set Webhook

`POST https://api.99digital.co.il/facebook/setWebhook`

This endpoint allows you to set (or clear) the webhook URL of a connection, where we send you what happens on your Facebook Page or Instagram account.

What we send to this URL, and when, is explained on the
[Webhook Events](https://docs.99digital.co.il/facebook-api/webhooks/webhook-events) page, with one page
for every kind of event:
[Facebook Comment](https://docs.99digital.co.il/facebook-api/webhooks/facebook-comment),
[Facebook Post](https://docs.99digital.co.il/facebook-api/webhooks/facebook-post),
[Facebook Lead](https://docs.99digital.co.il/facebook-api/webhooks/facebook-lead),
[Instagram Comment](https://docs.99digital.co.il/facebook-api/webhooks/instagram-comment) and
[Instagram Post](https://docs.99digital.co.il/facebook-api/webhooks/instagram-post).

- The webhook URL belongs to **one connection** (one `from`). A Facebook
  Page connection and an Instagram connection each have their own `from`,
  so each one needs its own call: you can give them different URLs, or the
  same URL.
- Everything we send for a connection goes to its one URL, and `event` in
  the payload tells you what arrived. For a Messenger connection, the same
  URL also receives the `sendStatus` of the messages you send.
- The change applies immediately. An empty `url` clears it: from then on,
  nothing is sent for this connection until you set a URL again.

:::warning
When a connection is onboarded again (for example, to renew its access),
you keep the same `from` and `apiKey`, but its webhook URL is erased. Call
Set Webhook again right after every onboarding, or you stop receiving
webhooks for that connection.
:::

**Settings**:

| Setting | Value |
| --- | --- |
| URL | `https://api.99digital.co.il/facebook/setWebhook` |
| Method | JSON via POST |
| Header | Your API key for the service (the `apiKey` header) |

**Body**:

| Parameter | Description / Example | Mandatory | Example |
| --- | --- | --- | --- |
| from | The ID you received for the connection. Works for every connection type (Facebook Pages, Instagram, Facebook Messenger and Instagram Messenger) | yes | 463745743546345 |
| url | Your webhook URL: `https://` only, on a public host, up to 2,000 characters (see the URL rules below). Send an empty string `""` to clear it | yes | https://your-server.example.com/99digital/facebook-webhook |

**URL rules** (a URL that breaks them is not saved, and you get reason 9):

- It must start with `https://`. `http://` and every other scheme are
  refused.
- The host can't be `localhost`, a name that ends with `.localhost` or
  `.internal`, or a private, loopback or link-local IP address
  (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `127.0.0.0/8`,
  `169.254.0.0/16`, `0.0.0.0/8`, `::1`, `::`, `fc00::/7`, `fe80::/10`,
  also when written as an IPv4-mapped IPv6 address such as
  `::ffff:10.0.0.1`).
- An IPv4 address must be in the normal dotted form (`203.0.113.10`).
  Short, decimal, hex or octal forms (`127.1`, `2130706433`,
  `0x7f000001`) are refused. IPv6 addresses are accepted unless they are
  in a blocked range: loopback (`::1`), private (unique-local,
  `fc00::/7`), link-local (`fe80::/10`), unspecified (`::`), or an
  IPv4-mapped address of a blocked IPv4 range (`::ffff:10.0.0.1`).
- A host name must exist, and none of its addresses may be in the ranges
  above: if even one of them is, the URL is refused.
- A host name with non-English letters must be sent in its punycode form
  (`xn--…`).

**Response**:

```json
{
  "status": "OK",
  "from": "463745743546345",
  "timestamp": 1795600000,
  "reason": 1,
  "url": "https://your-server.example.com/99digital/facebook-webhook"
}
```

**Response-Explain**:

| Parameter | Description |
| --- | --- |
| status | OK or FAIL |
| from | Your ID for the service |
| timestamp | Time stamp of the message |
| url | The webhook URL that is now saved for this connection. Empty when you cleared it |

**reason**:

| Value | Information |
| --- | --- |
| 1 | Not FAIL. The status is OK |
| 2 | Your "from" account does not exist (for example, its onboarding is not finished yet) or is missing, or JSON syntax error. Also when the check of your host name's DNS was slow or failed for a moment: send the same request again |
| 3 | Wrong apiKey (the apiKey header is missing or wrong) |
| 5 | 'url' is missing (or is not a string), or it is not a valid URL: for example, it has no scheme or no host, or it has spaces, backslashes or control characters |
| 7 | The connection is not active (it was disabled) |
| 8 | 'url' is longer than 2,000 characters |
| 9 | The URL is not allowed: it is not `https://`, or its host is (or resolves to) a private or internal address, or the host name does not exist. See the URL rules above |

**Remarks**:

- A `url` of spaces only is the same as an empty string: it clears the
  URL.
- Events that happen while no URL is set are not sent to you, not even
  after you set one.

## Authentication

`apiKey` in the header — Your API key for the service.

## Request body

Content type: `application/json` (required)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | string | Yes | The ID you received for the connection. Works for every connection type (Facebook Pages, Instagram, Facebook Messenger and Instagram Messenger). Example: `463745743546345`. |
| `url` | string | Yes | Your webhook URL: `https://` only, on a public host, up to 2,000 characters (see the URL rules above). Send an empty string `""` to clear it: from then on, nothing is sent for this connection until you set a URL again. Max length: 2000. Example: `https://your-server.example.com/99digital/facebook-webhook`. |

### Example: Set the URL

Send every event of this connection to your server.

```json
{
  "from": "463745743546345",
  "url": "https://your-server.example.com/99digital/facebook-webhook"
}
```

### Example: Clear the URL

Stop all webhooks of this connection.

```json
{
  "from": "463745743546345",
  "url": ""
}
```

## Responses

### 200 — The request was processed. Both a successful and a failed request answer with HTTP 200 — check `status`, and `reason` when it is FAIL.

Content type: `application/json`

| Field | Type | Description |
| --- | --- | --- |
| `status` | string | (one of: OK) OK or FAIL. `OK` — the URL is saved and applies immediately. Always `OK`. |
| `from` | string | (one of: OK) Your ID for the service. Example: `463745743546345`. |
| `timestamp` | integer | (one of: OK) Time stamp of the message (Unix time, in seconds). Example: `1795600000`. |
| `reason` | integer | (one of: OK) 1 — not FAIL, the status is OK. Always `1`. |
| `url` | string | (one of: OK) The webhook URL that is now saved for this connection. Empty when you cleared it. Example: `https://your-server.example.com/99digital/facebook-webhook`. |
| `status` | string | (one of: FAIL) FAIL — the request was not carried out. `reason` says why. Always `FAIL`. |
| `reason` | integer | (one of: FAIL) The status explanation in case of FAIL. One of: `2` — Your "from" account does not exist (for example, its onboarding is not finished yet) or is missing, or JSON syntax error. Also when the check of your host name's DNS was slow or failed for a moment: send the same request again; `3` — Wrong apiKey (the apiKey header is missing or wrong); `5` — 'url' is missing (or is not a string), or it is not a valid URL: for example, it has no scheme or no host, or it has spaces, backslashes or control characters; `7` — The connection is not active (it was disabled); `8` — 'url' is longer than 2,000 characters; `9` — The URL is not allowed: it is not `https://`, or its host is (or resolves to) a private or internal address, or the host name does not exist. See the URL rules above. |

#### Example: OK

The URL is saved.

```json
{
  "status": "OK",
  "from": "463745743546345",
  "timestamp": 1795600000,
  "reason": 1,
  "url": "https://your-server.example.com/99digital/facebook-webhook"
}
```

#### Example: OK — cleared

The URL is cleared; nothing is sent for this connection.

```json
{
  "status": "OK",
  "from": "463745743546345",
  "timestamp": 1795600000,
  "reason": 1,
  "url": ""
}
```

#### Example: Reason 5

'url' is missing, or it is not a valid URL.

```json
{
  "status": "FAIL",
  "reason": 5
}
```

#### Example: Reason 9

The URL is not allowed — for example `http://`, `localhost`, a private IP address, or a host name that does not exist.

```json
{
  "status": "FAIL",
  "reason": 9
}
```
