curl -X GET 'https://api.newrelic.com/v2/applications.json' -H 'Api-Key: NRAK-3T8WTXSP4KJSLMG74WHR5I3SSY9' -H 'Content-Type: application/json'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 799 0 799 0 0 809 0 --:--:-- --:--:-- --:--:-- 811{"applications":[{"id":1508171253,"name":"devopsschool","language":"java","health_status":"red","reporting":false,"settings":{"app_apdex_threshold":0.5,"end_user_apdex_threshold":7.0,"enable_real_user_monitoring":true,"use_server_side_config":false},"links":{"application_instances":[],"servers":[],"application_hosts":[]}}],"links":{"application.servers":"/v2/servers?ids={server_ids}","application.server":"/v2/servers/{server_id}","application.application_hosts":"/v2/application/{application_id}/hosts?ids={host_ids}","application.application_host":"/v2/application/{application_id}/hosts/{host_id}","application.application_instances":"/v2/application/{application_id}/instances?ids={instance_ids}","application.application_instance":"/v2/application/{application_id}/instances/{instance_id}"}}
Code language: JavaScript (javascript)
Here’s a step-by-step guide to correctly create alerts via New Relic API, with proper handling of:
typecondition_scopeentitiesmetric
This will help you avoid common errors like using the wrong entity type or unsupported metrics.
โ STEP-BY-STEP GUIDE TO NEW RELIC ALERT API SETUP
๐น STEP 1: Decide the Alert Use Case
What are you monitoring?
| Use Case | API Type | Domain | Scope/Condition |
|---|---|---|---|
| App performance (APM) | apm_app_metric | APM | condition_scope: application |
| Infrastructure (host, containers) | infra_metric | INFRA | where_clause |
| Browser monitoring | browser_metric | BROWSER | application |
| Synthetics (Ping/API checks) | synthetics | SYNTH | per monitor |
| Custom metrics | user_defined | depends | APM only |
๐น STEP 2: Find the Correct Entity (ID or GUID)
๐ธ For APM App: Use numeric App ID
curl -X GET 'https://api.newrelic.com/v2/applications.json' \
-H 'Api-Key: YOUR_API_KEY'
Code language: JavaScript (javascript)
Use
idfrom the output inentities: [YOUR_APP_ID].
๐ธ For Infrastructure (Host): Use hostname or tag via where_clause
๐น STEP 3: Choose the Right type, condition_scope, and metric
โ APM (Application Metrics)
curl -X POST 'https://api.newrelic.com/v2/alerts_conditions/policies/<policy_id>.json' \
-H 'Api-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"condition": {
"type": "apm_app_metric",
"name": "Error Rate Alert",
"enabled": true,
"condition_scope": "application",
"entities": [1508171253],
"metric": "error_percentage",
"terms": [
{
"duration": "5",
"operator": "above",
"priority": "critical",
"threshold": "5",
"time_function": "all"
}
]
}
}'
Code language: PHP (php)
โ Allowed APM Metrics:
apdexerror_percentageresponse_time_webresponse_time_backgroundthroughput_webthroughput_background
โ Infrastructure Host Metrics
curl -X POST 'https://api.newrelic.com/v2/alerts_conditions.json' \
-H 'Api-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"condition": {
"type": "infra_metric",
"name": "High CPU Usage on Host",
"enabled": true,
"policy_id": 6269799,
"event_type": "SystemSample",
"select_value": "cpuPercent",
"comparison": "above",
"critical_threshold": {
"value": 80,
"duration_minutes": 5,
"time_function": "all"
},
"where_clause": "hostname = '\''ip-10-0-0-1'\''"
}
}'
Code language: PHP (php)
โ
Common Infra Metrics (event_type: SystemSample)
cpuPercentmemoryUsedBytesdiskUsedPercentloadAverageOneMinute
โ Synthetics Monitor Example
curl -X POST 'https://api.newrelic.com/v2/alerts_synthetics_conditions/policies/<policy_id>.json' \
-H 'Api-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"synthetics_condition": {
"name": "Ping Failure",
"monitor_id": "your-monitor-id",
"enabled": true,
"runbook_url": "",
"terms": [
{
"duration": "5",
"operator": "above",
"priority": "critical",
"threshold": "0",
"time_function": "all"
}
]
}
}'
Code language: PHP (php)
๐น STEP 4: Test the Entity Type (Optional)
If unsure whether an entity is valid for APM alert:
{
actor {
entity(guid: "GUID_HERE") {
name
domain
type
guid
}
}
}
Code language: JavaScript (javascript)
Use via: https://api.newrelic.com/graphiql
๐ Summary Reference Table
| Monitoring Target | API type | Metric Source | Entity/Where |
|---|---|---|---|
| APM App | apm_app_metric | App-level (error_percentage, etc.) | entities: [APP_ID] |
| Host (infra) | infra_metric | Host-level (cpuPercent, memoryUsed) | where_clause |
| Browser app | browser_metric | Page load, JS errors | App ID |
| Synthetics | synthetics | Monitor failure % or duration | Monitor ID |
| Custom metrics | user_defined | Custom instrumented metrics | APM app ID |
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals