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 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.

Related Posts

Should A Student Use ChatGPT To Learn DevOps Instead Of Courses?

As a student looking to learn DevOps, you might be wondering if ChatGPT is a good alternative to traditional courses. While there are some benefits to using…

Read More

Top 10 Digital Signature Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, digital transformation has reshaped the way businesses manage documents, sign agreements, and engage with clients. Digital signatures have become an essential component of this…

Read More

Top 10 Graphics Design Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, graphics design tools are more essential than ever for businesses, content creators, designers, and marketers across industries. From creating brand identities and advertising materials…

Read More

Top 10 Presentation Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, creating engaging and impactful presentations is more than just slides with bullet points—it’s about telling a story, conveying ideas visually, and keeping your audience…

Read More

How to Optimize Your headless CMS for Multilingual Websites

A multilingual site enables a company to internationalize itself to different audiences for better engagement and ultimately, international brand awareness. However, without the proper considerations with the…

Read More

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

Introduction In 2026, AI SEO tools have become indispensable for digital marketers, businesses, and content creators aiming to dominate search engine rankings. These tools leverage artificial intelligence…

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