Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

New Relic API Guide – Step-by-Step Tutorial with Example

Here is a step-by-step tutorial on how to work with the New Relic API, including how to create an alert condition using the API.


🚀 New Relic API Guide – Step-by-Step Tutorial with Example (Create Alert)


🧰 Prerequisites

RequirementDescription
✅ New Relic AccountEnsure you have access to New Relic
✅ API KeyYou need a Personal API Key (not ingest license)
✅ Account IDYou can find your Account ID in the top-right profile dropdown in NR One
curl or PostmanUse curl, Postman, or any HTTP client for making API requests

📘 Step 1: Get Your API Key & Account ID


📘 Step 2: Understand the API Base URL

Use the GraphQL endpoint for most operations:

https://api.newrelic.com/graphql
Code language: JavaScript (javascript)

Some older REST endpoints (like for alerts) are still at:

https://api.newrelic.com/v2/...
Code language: JavaScript (javascript)

📘 Step 3: Create an Alert Policy (REST API)

API Endpoint:

POST https://api.newrelic.com/v2/alerts_policies.json
Code language: JavaScript (javascript)

Headers:

Api-Key: <YOUR_API_KEY>
Content-Type: application/json
Code language: HTTP (http)

Request Body:

{
  "policy": {
    "name": "High CPU Usage Policy",
    "incident_preference": "PER_POLICY"
  }
}
Code language: JSON / JSON with Comments (json)

Example cURL:

curl -X POST 'https://api.newrelic.com/v2/alerts_policies.json' \
  -H 'Api-Key: YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
        "policy": {
          "name": "High CPU Usage Policy",
          "incident_preference": "PER_POLICY"
        }
      }'
Code language: PHP (php)

Response will include id — save this policy_id.


📘 Step 4: Create an Alert Condition (e.g., High CPU)

API Endpoint:

POST https://api.newrelic.com/v2/alerts_conditions/policies/<policy_id>.json
Code language: HTML, XML (xml)

Example:

curl -X POST 'https://api.newrelic.com/v2/alerts_conditions/policies/6269799.json' \
  -H 'Api-Key: NRAK-3T8WTXSP4KJSLMG74WHR5I3SSY9' \
  -H 'Content-Type: application/json' \
  -d '{
        "condition": {
          "type": "apm_app_metric",
          "name": "Error Rate Alert for devopsschool",
          "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)

🔍 Explanation:

  • "type": "apm_app_metric" — type of monitoring (can also be "infra_metric", "nrql" etc.)
  • "entities" — Application or host ID (can be fetched from other APIs)
  • "metric": "cpu_percent" — Metric name
  • "terms" — Defines the condition (thresholds, duration, etc.)

📘 Step 5: Verify the Alert in New Relic UI

  • Go to Alerts & AIAlert Policies
  • Check if “High CPU Usage Policy” and “CPU Alert” are visible and enabled.

🧠 Bonus: List Alert Policies (Get API)

curl -X GET 'https://api.newrelic.com/v2/alerts_policies.json' \
  -H 'Api-Key: YOUR_API_KEY'
Code language: JavaScript (javascript)

🛠️ Advanced: Create Alerts using NRQL Condition (for Logs or Custom Queries)

Endpoint:

POST https://api.newrelic.com/v2/alerts_nrql_conditions/policies/<policy_id>.json
Code language: HTML, XML (xml)

Example:

curl -X POST "https://api.newrelic.com/v2/alerts_nrql_conditions/policies/123456.json" \
  -H "Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "nrql_condition": {
      "name": "Too many 404s",
      "enabled": true,
      "type": "static",
      "nrql": {
        "query": "SELECT count(*) FROM Log WHERE message LIKE '%404%'"
      },
      "terms": [
        {
          "duration": "5",
          "operator": "above",
          "priority": "critical",
          "threshold": "10",
          "time_function": "all"
        }
      ]
    }
  }'
Code language: PHP (php)

🧾 Summary

StepActionAPI Used
1Create Alert Policy/v2/alerts_policies.json
2Create Metric or NRQL Condition/v2/alerts_conditions/...
3(Optional) Associate NotificationNotification Channels API

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Here’s a clear and professional explanation of the three related concepts you asked about — all of which are critical parts of secure software development, especially in…

Read More

Top 10 AI Code Review Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI code review tools have become essential for developers aiming to enhance code quality, streamline workflows, and accelerate software delivery. These tools leverage advanced…

Read More

Top 10 Expense Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction Expense management tools are critical for businesses of all sizes in 2026 as they help streamline financial processes, improve budgeting, ensure compliance, and enhance financial visibility….

Read More

Top 10 Web Application Firewall (WAF) Tools in 2026: Features, Pros, Cons & Comparison

Introduction In the rapidly evolving landscape of cybersecurity, Web Application Firewalls (WAFs) have become a critical component in defending web applications from malicious attacks such as SQL…

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devices—laptops, desktops, mobile devices, and other endpoints—that connect to their networks. With the…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x