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

# Route alerts to PagerDuty

> Add a PagerDuty destination, send only sev-1 incidents to it with a route, and check that deliveries arrive.

A destination is a place that receives incidents. A route chooses which incidents go to which
destinations. This recipe adds a PagerDuty destination and a route that pages only for `sev-1`
incidents. Both steps need `notifications:write`. Reading deliveries needs `notifications:read`.

You need a PagerDuty service with an **Events API V2** integration. Put its integration key in an
environment variable, so that it does not appear in your shell history or in a prompt:

```bash theme={null}
export PAGERDUTY_INTEGRATION_KEY="YOUR_INTEGRATION_KEY"
```

## Add the destination

> [tab] CLI
>
> ```bash theme={null}
> squasher notifications destinations create --project "$SQUASHER_PROJECT_ID" \
>   --type pagerduty --label "PagerDuty on-call" \
>   --config "{\"integrationKey\":\"$PAGERDUTY_INTEGRATION_KEY\"}" --json
> ```

> [tab] MCP
>
> This write needs **Full access**. Paste the integration key into the snippet only when the
> person gave it to you for this task.
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> return await squasher.request({
>   method: "POST",
>   path: `/v1/projects/${projectId}/notifications/destinations`,
>   body: {
>     type: "pagerduty",
>     label: "PagerDuty on-call",
>     config: { integrationKey: "YOUR_INTEGRATION_KEY" },
>   },
> });
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl -X POST "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/notifications/destinations" \
>   -H "x-squasher-key: $SQUASHER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d "{
>     \"type\": \"pagerduty\",
>     \"label\": \"PagerDuty on-call\",
>     \"config\": { \"integrationKey\": \"$PAGERDUTY_INTEGRATION_KEY\" }
>   }"
> ```

The response hides the key. Keep the destination `id`:

```json theme={null}
{
  "destination": {
    "id": "<uuid>",
    "type": "pagerduty",
    "label": "PagerDuty on-call",
    "enabled": true,
    "configPreview": { "integrationKey": "<last four characters>" },
    "createdAt": "<ISO time>",
    "updatedAt": "<ISO time>"
  }
}
```

To map severities another way, add `severityMap` to `config`, for example
`{ "sev-1": "critical", "sev-2": "critical" }`. See [PagerDuty](https://docs.squasher.ai/integrations/pagerduty.md).

## Add the route

The route matches `sev-1` incidents. Its `events` list adds `acknowledged`, so that PagerDuty
acknowledges the alert too. Without `events`, a route sends only `opened` and `resolved`.

> [tab] CLI
>
> ```bash theme={null}
> squasher notifications routes create --project "$SQUASHER_PROJECT_ID" \
>   --name "SEV-1 pages" --destination DESTINATION_ID \
>   --input '{"conditions":{"severities":["sev-1"],"events":["opened","acknowledged","resolved"]}}' \
>   --json
> ```

> [tab] MCP
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> return await squasher.request({
>   method: "POST",
>   path: `/v1/projects/${projectId}/notifications/routes`,
>   body: {
>     name: "SEV-1 pages",
>     conditions: {
>       severities: ["sev-1"],
>       events: ["opened", "acknowledged", "resolved"],
>     },
>     destinationIds: ["DESTINATION_ID"],
>   },
> });
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl -X POST "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/notifications/routes" \
>   -H "x-squasher-key: $SQUASHER_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "name": "SEV-1 pages",
>     "conditions": {
>       "severities": ["sev-1"],
>       "events": ["opened", "acknowledged", "resolved"]
>     },
>     "destinationIds": ["DESTINATION_ID"]
>   }'
> ```

The response has the route:

```json theme={null}
{
  "route": {
    "id": "<uuid>",
    "name": "SEV-1 pages",
    "enabled": true,
    "isDefault": false,
    "conditions": { "severities": ["sev-1"], "events": ["opened", "acknowledged", "resolved"] },
    "scope": {},
    "behavior": {},
    "destinationIds": ["<destination uuid>"]
  }
}
```

Other filters are in [Add a route with filters](https://docs.squasher.ai/features/alerts.md#add-a-route-with-filters). To
change the destinations of a route later, use `squasher notifications routes set-destinations`.

## Check the deliveries

> [!WARNING]
>
> A test through a PagerDuty destination sends a real `trigger` event and opens an alert in
> PagerDuty. Resolve that alert in PagerDuty afterward. Do not run a test on a service that pages a
> person at night.

Every delivery attempt is recorded with its status code. `squasher notifications destinations test DESTINATION_ID`
sends a test event. Then read the recent deliveries:

> [tab] CLI
>
> ```bash theme={null}
> squasher notifications deliveries --project "$SQUASHER_PROJECT_ID" --limit 5 --json
> ```

> [tab] MCP
>
> ```javascript theme={null}
> const projectId = "YOUR_PROJECT_ID";
> return await squasher.request({
>   method: "GET",
>   path: `/v1/projects/${projectId}/notifications/deliveries`,
>   query: { limit: 5 },
> });
> ```

> [tab] REST API
>
> ```bash theme={null}
> curl "https://api.squasher.ai/v1/projects/$SQUASHER_PROJECT_ID/notifications/deliveries?limit=5" \
>   -H "x-squasher-key: $SQUASHER_API_KEY"
> ```

Each delivery has this shape. A failed delivery has `success: false` and an `errorMessage`:

```json theme={null}
{
  "deliveries": [
    {
      "id": "<uuid>",
      "destinationId": "<uuid>",
      "routeId": "<uuid>",
      "incidentId": "<uuid>",
      "event": "opened",
      "attempt": 1,
      "success": true,
      "statusCode": "<HTTP status code>",
      "errorMessage": null,
      "sentAt": "<ISO time>",
      "nextAttemptAt": null
    }
  ]
}
```

To remove the setup, delete the route and then the destination with
`squasher notifications routes delete ROUTE_ID --yes` and
`squasher notifications destinations delete DESTINATION_ID --yes`.

## Next steps

> [card] [PagerDuty](https://docs.squasher.ai/integrations/pagerduty.md)
>
> What Squasher sends and how severities map.

> [card] [Notifications API](https://docs.squasher.ai/api-reference/alerts.md)
>
> Every destination type and route field.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.