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

# Webhook Integration

To add your webhook to Metoro, go to the [integrations](https://us-east.metoro.io/integrations) page and click on the `Add Webhook` button.
Fill in the details of the webhook and click on the `Add Webhook` button.

<img src="https://mintcdn.com/metoro/JQ7xkDXZJ0ErZc8O/images/webhook_integration.png?fit=max&auto=format&n=JQ7xkDXZJ0ErZc8O&q=85&s=b0f8111b3a50d075429580798b8f522a" alt="Add Webhook Integration modal with fields for name, URL, HTTP method, headers, and body template" width="2216" height="1420" data-path="images/webhook_integration.png" />

* **Name** (required): The name of the webhook
* **URL** (required): The URL of the webhook. You can use template variables in the URL for dynamic values (see template variables section below)
* **HTTP Method**: The HTTP method to use when sending the webhook. Default is `POST`
* **Headers**: Additional headers to send with the webhook. If you are sending a POST request, `Content-Type` header is added by default with the value `application/json`. You can add more headers by clicking on the `Add Header` button.
* **Body Template** (optional): If you would like to send a custom body with the webhook, you can use the body template. Leave empty to use the default JSON payload. You can use template variables in your webhook body (see template variables section below).

## Template Variables

You can use the following template variables in both the webhook URL and body template:

* `$alert_name`: The name of the alert
* `$alert_description`: The description of the alert
* `$alert_uuid`: The UUID of the alert definition
* `$alert_fire_uuid`: The UUID of the specific alert fire instance
* `$alert_state`: The state of the alert (either "firing" or "resolved")
* `$deep_link`: Direct link to view the alert details in Metoro
* `$environment`: \[**Deprecated** - use `$attributes` instead] Environment context of the alert. It's set for Kubernetes and Log alerts only or if the alert has a group by with `environment`
* `$service`:  \[**Deprecated** - use `$attributes` instead] The service associated with the alert. It's set for Kubernetes and Log alerts only or if the alert has a group by with `service.name`/`service_name`/`client.service.name`/`server.service.name`.
* `$fired_at`: Unix Timestamp when alert was fired
* `$resolved_at`: Unix Timestamp when alert was resolved/recovered.
* `$breaching_datapoint_value`: The last metric/trace value that triggered the alert. It's set for Trace and Metric alerts only.
* `$breaching_datapoint_time`: Unix Timestamp of the last breaching value. It's set for Trace and Metric alerts only.
* `$metric_name`: Name of the metric that triggered the alert. It's set for Trace and Metric alerts only.
* `$attributes`: List of attribute key and value pairs (in `key: value` format) for which the alert is firing. Only set when you use a group by in your alert.

## Examples

### URL Examples

You can include template variables directly in your webhook URL:

```
https://api.example.com/webhook?alert=$alert_name&value=$breaching_datapoint_value
https://api.example.com/alerts/$alert_uuid/fire/$alert_fire_uuid
https://api.example.com/webhook?state=$alert_state&service=$service
```

### Body Template Examples

1. **JSON format:**

```json theme={null}
{ 
  "alert": "$alert_name", 
  "alert_uuid": "$alert_uuid",
  "alert_fire_uuid": "$alert_fire_uuid",
  "state": "$alert_state",
  "value": "$breaching_datapoint_value",
  "deep_link": "$deep_link" 
}
```

2. **Plain text format:**

```text theme={null}
Alert $alert_name ($alert_uuid) is $alert_state with value $breaching_datapoint_value
```

3. **XML format:**

```xml theme={null}
<alert>
  <name>$alert_name</name>
  <uuid>$alert_uuid</uuid>
  <fire_uuid>$alert_fire_uuid</fire_uuid>
  <state>$alert_state</state>
  <value>$breaching_datapoint_value</value>
</alert>
```

<Note>
  Remember to set the `Content-Type` header in the headers section with the appropriate value.
</Note>

After your webhook is added, you can select your webhook as a destination in the alert creation wizard.

<img src="https://mintcdn.com/metoro/JQ7xkDXZJ0ErZc8O/images/webhook_alert_destination.png?fit=max&auto=format&n=JQ7xkDXZJ0ErZc8O&q=85&s=7078d43314092f43d41a97bfda473418" alt="Alert destination selector with Webhook option selected and webhook dropdown showing available webhooks" width="2192" height="814" data-path="images/webhook_alert_destination.png" />

<Tip>
  You can check webhook delivery status and errors in Metoro Logs view. This provides visibility into successful deliveries and any issues encountered.
  Go to the [Logs page](https://us-east.metoro.io/logs) and filter by `environment=metoro-internal` and `service.name=metoro-webhooks` to see webhook notifications that are successfully sent or failed with errors.
</Tip>
