Defining Datadog Monitors with the API and JSON - Structure and Pitfalls
The JSON for a monitor created through the API or Terraform centers on type and query, to which you add options, which holds thresholds and how silence is handled, and message, which also serves as the notification destination. This article follows everything from how to write log monitor conditions to pre-checking with validate and how the keys map to Terraform.
Create the first monitor in the UI and read the JSON back
Before assembling keys by hand, save one monitor on the creation screen and then read it back through the API; this shows you in one pass how the fields on the screen correspond to the keys in the JSON. The monitor type and evaluation window you chose on the screen are condensed into two strings, type and query, while the threshold and delay fields are scattered under options. You read it back with GET /api/v1/monitor/{monitor_id}, and because the returned JSON also contains read-only keys such as id and overall_state, drop them when you copy the definition into IaC (as of October 2026; source: Monitors). If you are moving to Terraform, there is also Export to Terraform, which generates a definition from the monitor you select in the Monitor List; looking at the generated output first reduces mix-ups between keys (source: Monitor List). The thinking behind where to place thresholds is covered in detail in the explanation of Datadog Monitors; in JSON, those decisions are simply replaced by numbers and strings.
The two keys that define the content are type and query
In the description of the create request, name and message are also marked as required, but if you omit either one it is filled in automatically based on the query, so the core that defines the content is the two keys type and query (as of October 2026; source: Create a monitor). The automatically filled name and body merely trace the expression and are hard for recipients to read, so for a monitor you put into operation, write all four yourself and send them.
| Key | Type | What goes in it |
|---|---|---|
| type (required) | Enum | The monitor type. This determines the grammar of the query |
| query (required) | String | The expression to evaluate. A comparison operator and threshold at the end |
| name (required, but filled in automatically if omitted) | String | The notification subject and the name shown in the list |
| message (required, but filled in automatically if omitted) | String | The notification body. Its @ handles also serve as the recipients |
| options | Object | Thresholds, handling when data stops arriving, delays, renotification |
| tags | Array of strings | Tags attached to the monitor itself |
| priority | Integer | Severity from 1 (high) to 5 (low) |
| restricted_roles | Array of strings | UUIDs of the roles allowed to edit |
The value of type is what tends to confuse people in the JSON they read back. The enum includes both metric alert and query alert, but in the create API's table of monitor types, metric, anomaly, forecast, and outlier monitors are all assigned to query alert. This is why a metric monitor created in the UI comes back as query alert; you did not create a different type. Look up the UUIDs for restricted_roles from the Roles API and write them as IDs, not names.
The query grammar differs completely by type
query is a single string, but the grammar inside it differs by type, right down to the sequence of functions. Metrics put the aggregation function and evaluation window first, logs and processes chain methods together, and service checks start with the check name and count occurrences of each status. The comparison operator and number at the end are the alert threshold; you can also write the same value in critical under options.thresholds, but the warning threshold can only be placed on the options side (source: Monitor API Options).
| type | Query form |
|---|---|
| query alert (metrics) | time_aggr(time_window):space_aggr:metric{tags} [by {key}] operator # |
| log alert | logs(query).index(index_name).rollup(rollup_method[, measure]).last(time_window) operator # |
| trace-analytics alert (APM) | The create API description has no grammar for the expression, so create one in the UI and copy the exported form. To watch APM metrics, use the query alert form |
| service check | "check".over(tags).last(count).by(group).count_by_status() |
| process alert | processes(search).over(tags).rollup('count').last(timeframe) operator # |
| composite | 12345 && 67890 (joins the IDs of other monitors with logical operators) |
Adding by {key} to a metric expression makes it a multi alert, which raises a separate alert for each tag value; without it, there is one alert for the whole. The rollup in a log expression is chosen from count / avg / cardinality, and for the latter two you write the name of the thing being measured as the second argument. Following the grammar, an expression that counts error logs every 5 minutes takes the following form.
logs("service:web status:error").index("INDEX_NAME").rollup("count").last("5m") > 50A log monitor counts only indexed logs, so lines dropped by exclusion filters are not included in the count. How zero results are handled and how to use below 1 are summarized in the glossary entry for Log Monitor.
Thresholds and the handling of silence are decided inside options
The keys in options are divided into common keys that apply to all types and keys specific to each type. For metrics, the thresholds key is a dictionary of critical and warning plus their respective recovery thresholds critical_recovery / warning_recovery; for logs and service checks, you write it as a dictionary keyed by status. A recovery threshold is an additional condition for an alert to clear, and it keeps notifications from flipping back and forth each time the value wavers near the boundary.
| Key | Default | Effect |
|---|---|---|
| new_group_delay | 60 (seconds) | Grace period before a newly appearing group is evaluated. Prevents false alerts from containers that spike right after starting |
| evaluation_delay | null | Delays evaluation by a number of seconds. For data that is backfilled later, such as CloudWatch |
| require_full_window | false | Does not evaluate until a full window of data is available. false is recommended for sparse metrics |
| notify_no_data | false | Notifies when data stops arriving |
| no_data_timeframe | null | Number of minutes after data stops before notifying. If omitted, twice the evaluation window for query alerts and 24 hours for service checks |
| on_missing_data | Varies by type | How empty evaluations are handled for logs, APM, and so on |
| renotify_interval | null | How many minutes without resolution before renotifying |
| notify_by | null | At which tag granularity to notify. ["*"] treats it as a simple alert |
What tends to trip people up when moving to JSON is that the keys representing the state of no incoming data differ between metrics and logs. Metric expressions use the pair notify_no_data and no_data_timeframe, while log and trace expressions use the single key on_missing_data, whose value is chosen from default / show_no_data / show_and_notify_no_data / resolve. With the default, empty evaluations in count expressions are compared as 0, and in other expressions the last state continues to be shown. If you set evaluation_delay to 300 and the window to last_5m, the 7:00 evaluation reads data from 6:50 to 6:55. The concept of data gaps is covered in detail in the glossary entry for No Data.
Write the notification destination in the message body
There is no dedicated key for specifying recipients; the @ handles written in the body of message become the notification destinations as they are. When you want to change the recipients or wording by state, divide the body with opening and closing pairs of conditional variables and place the text and @ handles between them. State conditions such as is_alert and is_warning cannot be combined, because a monitor can be in only one state at a time, so use a separate block for each state (as of October 2026; source: Variables).
{{#is_alert}}
Error count {{value}} is over {{threshold}} @oncall@example.com
{{/is_alert}}
{{#is_recovery}}
Recovered @oncall@example.com
{{/is_recovery}}| Syntax | Effect |
|---|---|
| {{#is_alert}} to {{/is_alert}} | Shown only when it becomes an alert |
| {{#is_warning}} | Shown only on a warning |
| {{#is_recovery}} | When it recovers from ALERT / WARNING / UNKNOWN / NO DATA |
| {{#is_no_data}} | When it fires because data is missing |
| {{#is_match "host.role.name" "db"}} | When the value of a tag or attribute contains the string |
| {{#is_priority 'P1'}} | When the priority is P1 (P1 to P5) |
| {{value}} / {{threshold}} / {{warn_threshold}} | The value that breached / the alert threshold / the warning threshold |
Inside JSON you have to write line breaks as \n, so reading back a body you formatted on the screen and copying it is less likely to break. is_priority takes the characters P1 to P5, whereas priority in JSON is an integer from 1 to 5, so the same priority is written differently. The mechanism that resolves recipients from tags instead of writing @ handles one by one is Notification Rules, and how to create Slack and Teams destinations is covered in Setting Up Notifications to Slack and Teams.
Run validate before creating - mapping to Terraform keys
Creating is POST /api/v1/monitor, updating is PUT /api/v1/monitor/{monitor_id}, and retrieving is a GET to the same path. For a new definition, sending the same body to POST /api/v1/monitor/validate lets you check only its content without creating it, and a change to an existing monitor is checked with /api/v1/monitor/{monitor_id}/validate. The destination host varies with your organization's Datadog site: an organization on app.datadoghq.com uses api.datadoghq.com, and one on app.datadoghq.eu uses api.datadoghq.eu (as of October 2026; source: Monitors).
| API JSON | Terraform datadog_monitor |
|---|---|
| name / type / query / message | Arguments of the same name. All four are required |
| options.thresholds | monitor_thresholds block (critical / warning / recovery thresholds) |
| Each key in options (notify_no_data / on_missing_data / renotify_interval, etc.) | Arguments of the same name directly under the resource |
| priority (integer) | priority (passed as a string) |
| restricted_roles | Deprecated. Permissions are managed with the datadog_restriction_policy resource |
name and message, which the API fills in automatically when omitted, are arguments that Terraform will not accept unless you write them, so if you copy a JSON that omits them as is, you will be missing arguments. The fact that the nesting of options is removed and its keys are lined up directly under the resource is another difference that becomes easy to see when you compare it against the JSON you read back. How authentication is passed differs between examples in the official documentation: some pass two keys, an API key and an application key, and others pass an access token in Authorization: Bearer. You can tell which one your tooling uses from the environment variables in the example you follow (DD_API_KEY and DD_APP_KEY, or DD_BEARER_TOKEN). Creating a log monitor requires an application key whose scope has not been narrowed; the types of keys are summarized in the glossary entry for API Key, and importing existing monitors in Setting Up the Terraform Provider.
Check the operator, granularity, and priority on one exported monitor
You only find out that a monitor written in JSON does not fire, or fires too often, once values move in production, so comparing it key by key against one monitor created in the UI before you create it reduces rework. Check three places in this order: the end of the expression, the group granularity, and the notation of the priority.
- Whether the comparison operator and number at the end of the query are the same value as critical in options.thresholds (fixing only one causes a mismatch)
- Whether the presence or absence of by {key} is as intended. The tags written in notify_by are limited to a subset of the grouping tags in the query
- priority is written as an integer from 1 to 5 in JSON, and as the characters P1 to P5 in is_priority in message
- Whether require_full_window is set to true for sparse metrics (evaluations get skipped)
- Whether read-back-only keys such as id and overall_state are left in the creation body
To check it yourself, first retrieve one monitor from your own organization with GET, remove the read-back-only keys, send the body to validate, and see whether an error comes back. Once it passes, export the same monitor with Export to Terraform in the Monitor List and read the two side by side to see whether the keys line up according to the mapping in the table above. Once all this is in place, from the second monitor onward you only need to duplicate the JSON and rewrite query and message, which frees your time for the real work, such as deciding thresholds and choosing what to monitor.