# Alerts via the Admin API

## Setup

Create an API key (Atlas UI: Access Manager, API Keys) with project permissions, and add your automation IP to the API access list. API keys are separate from database users.

## Create an alert config

```bash
curl --user "[public-key]:[private-key]" --digest   --header "Accept: application/vnd.atlas.2023-11-15+json"   --header "Content-Type: application/json"   --request POST   "https://cloud.mongodb.com/api/atlas/v2/groups/[project-id]/alertConfigs"   --data '{
    "eventTypeName": "OUTSIDE_METRIC_THRESHOLD",
    "metricName": "CONNECTIONS",
    "operator": "GREATER_THAN",
    "threshold": 800,
    "units": "RAW",
    "notifications": [{
      "typeName": "PAGER_DUTY",
      "serviceKey": "[pager-duty-key]",
      "delayMin": 5
    }]
  }'
```

## Rules

- Thresholds come from your baseline, not defaults. Pull a week of the metric first.
- `delayMin` avoids paging on brief spikes; use it.
- Notification types include email, Slack, PagerDuty, webhook, and SMS. Route severity to the right channel.
- Store alert configs as code (Terraform has an alert config resource, or keep the curl in a script) so they are reviewed and reproducible.

## Verify

Trigger the condition in staging (a load test that crosses the threshold) and confirm the notification arrives with the right severity. Review alert configs quarterly.