# Receiving messages

Webhooks are automated messages sent from one web application to another when a specific event occurs.

To receive messages from 360dialog you need to specify webhook URL.&#x20;

There are 3 main events you can receive via the Webhook:

* `messages`: Used to notify you when you get a new message and what is in the new message.
* `statuses`: Used to notify you when there's a status change in a message you sent
* `errors`: When there are any out-of-band errors that occur in the normal operation of the application, this array provides a description of the error

### Webhook Response Requirements

Ensure your webhook servers can handle 3x the outgoing message traffic capacity and 1x the expected incoming message traffic capacity. For example, if you're sending 1000 messages per second with a 30% expected response rate, your servers should process up to 3000 message status webhooks and an additional 300 incoming message webhooks. [See more information about throughput here. ](broken://pages/QjiXsDi81KNPY17cn8QZ#messaging-throughput)

Configure and load test your webhook server to handle concurrent requests with the following latency standards:

* Median latency should not exceed 250ms.&#x20;
* Less than 1% of latency should exceed 1 second.

The API will attempt to re-deliver failed webhooks for up to 7 days with exponential backoff. **Failure to meet these guidelines may result in delays in processing incoming messages due to the exponential backoff mechanism.**

For a Webhook Notification to be considered by WhatsApp to be 'successfully delivered', the client must respond to the designated endpoint with a `HTTPS 200 OK` status code.&#x20;

If any other status code is returned, or if the client fails to correctly set up the endpoint to accept Notifications, the WhatsApp Business API Client considers it to be a 'failed delivery' and adds the Notification to its callback queue.&#x20;

360dialog also has a hard limit rule of 5 seconds for the client to return a 200 status code, after which it will register as a failed delivery.

To deploy a live webhook that can receive events from the WhatsApp Business API client, your webhook must have HTTPS support and a valid SSL certificate.

#### Recommendations

We recommend that you review our [best practices](broken://pages/LvBEsctZYW5iG5J8i0Ft) when implementing your solution.

To ensure that your WABA service performs reliably and consistently, you should optimize the webhook to be as fast as possible. Tips for doing so include the following:

* Design your service to respond as quickly, and as close to your network speed as possible.
* Respond with a `200` status code immediately after receiving a notification and storing i&#x74;**.** The callback's payload should **not** be processed before responding as this can lead to unacceptable delays; instead, send the response first then (asynchronously) process the payload.
* Reduce network latency by setting up your webhook server closer to 360dialog's datacenters (Central and Eastern Europe).
* Design your service to be scalable, and capable of performing well under high load/messaging volume, as increased latency may lead to your WABA number being disconnected. For further advice on scaling your service, [review our page on sizing your environment based on expected throughput.](/partner/onboarding/integration-best-practices/sizing-your-environment-based-on-expected-throughput.md)

## Set Webhook URL&#x20;

The Webhook URL is a resource address to which WhatsApp Servers send notifications triggered by specific events. A suitable webhook URL must be supplied by the client or by the Partner Software Provider / ISV.

{% hint style="warning" %}
If you generate a new API KEY, the webhook URL for that number will be removed. So you must reset it using the new API-KEY.&#x20;
{% endhint %}

#### Example setting webhook with Basic Auth

If the webhook URL needs to be authorized by user, `USER` and `PASS` should be provided in the header `Authorization` that contains `Basic base64(USER:PASS)`.&#x20;

Request body example for USER=`testuser` and PASS=`testpass`

{% tabs %}
{% tab title="Body" %}

```javascript
{
  "url": "https://www.example.com/webhook",
  "headers": {
    "Authorization": "Basic dGVzdHVzZXI6dGVzdHBhc3M="
  }
}
```

{% endtab %}
{% endtabs %}

### Set Webhook URL for phone number (recommended)

We recommend using this configuration to ensure the highest performance possible.

{% hint style="warning" %}
Webhook URLs or headers for Cloud API does not support *"*`_`*"*`(underscore)` or "`:xxxx`"`(port)`in (sub)domain names.

**Invalid webhook URL:** `https://your_webhook.example.com` \
**Valid webhook URL:** `https://yourwebhook.example.com`

**Invalid webhook URL:**`https://subdomain.your_webhook.example.com`**`:3000`** \
**Valid webhook URL:** `https://subdomain.yourwebhook.example.com`
{% endhint %}

Use this [endpoint](https://docs.360dialog.com/docs/messaging-api/api-reference/webhooks#post-v1-configs-webhook) to set the webhook URL. &#x20;

### Set Webhook per WABA&#x20;

Webhooks for Cloud API can be set at the WABA level, although this configuration is **not recommended** since it can decrease the messaging performance of the channels.&#x20;

This webhook URL will receive callbacks for all Cloud API numbers associated with that WABA.

To set the webhook URL per WABA, use this [endpoint](https://docs.360dialog.com/docs/messaging-api/api-reference/webhooks#post-waba_webhook).

When this endpoint is used with the `override_all` parameter set to `false`, it configures the supplied webhook for Cloud API numbers missing a specific phone number webhook setting. If `override_all` is `true`, the webhook applies across all Cloud API numbers within the WABA.

A typical inbound notification for WABA Webhook looks like the following:

```json
{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "WHATSAPP-BUSINESS-ACCOUNT-ID",
    "changes": [{
      "value": {
         "messaging_product": "whatsapp",
         "metadata": {
           "display_phone_number": "PHONE-NUMBER",
           "phone_number_id": "PHONE-NUMBER-ID"
         },
      # Additional arrays and objects
         "contacts": [{...}]
         "errors": [{...}]
         "messages": [{...}]
         "statuses": [{...}]
      },
      "field": "messages"
    }]
  }]
}
```

Components (`contacts`, `errors`, `messages`, `statuses`) are inside `entry.changes.value`.

### Delivery prioritization

Cloud API allows configuring webhooks at a Phone Number and WABA Webhook level. For callback delivery, webhooks are prioritized as below:

* **Primary is Phone Number Webhook:** This is the preferred route. If set, it overrides any other webhook configuration for callbacks.
* **Secondary is WABA Webhook**: This route is used for callback delivery only if the primary phone number webhook is not configured.
* **Fallback:** No Webhook Configured - If neither webhook is set, the system will return an empty response when attempting callbacks.

## Get Webhook URL

### Get phone number Webhook URL

If the phone number webhook URL is set, use this [endpoint](https://docs.360dialog.com/docs/messaging-api/api-reference/webhooks#get-v1-configs-webhook) to retrieve the existing resource.&#x20;

### Get WABA Webhook URL

Use this [endpoint](https://docs.360dialog.com/docs/messaging-api/api-reference/webhooks#get-waba_webhook) to check the current WABA webhook URL:

## Receiving notifications for incoming messages

When a customer replies or sends a message to the business, a HTTP POST request is sent to your webhook. [Text message webhook example](https://docs.360dialog.com/partner/integrations-and-api-development/webhook-events-and-setup/webhook-events-partner-and-messaging-api#text-messages). \
\
All webhook types are described in our documentation:

{% content-ref url="/pages/fpiZM6bgn9YcWqPSatjX" %}
[Webhook Events (Partner & Messaging API)](/partner/onboarding/webhook-events-and-setup/webhook-events-partner-and-messaging-api.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.360dialog.com/partner/messaging/sending-and-receiving-messages/receiving-messages-via-webhook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
