NerdGraph: Automating New Relic With the GraphQL API

Everything in the UI is available through the API

NerdGraph is New Relic's GraphQL API. It lets you query data, manage configuration, and automate operations — anything from running NRQL in scripts to bulk-tagging thousands of entities.

Getting Started

  • Create a User API key in New Relic
  • Explore with the NerdGraph GraphiQL explorer in the UI
  • Endpoint: https://api.newrelic.com/graphql (EU accounts use the EU endpoint)

Running NRQL From Node.js

const query = `{
  actor {
    account(id: ${process.env.NR_ACCOUNT_ID}) {
      nrql(query: "SELECT count(*) FROM Transaction FACET appName SINCE 1 day ago") {
        results
      }
    }
  }
}`;

const res = await fetch('https://api.newrelic.com/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', 'API-Key': process.env.NR_USER_KEY },
  body: JSON.stringify({ query }),
});
const data = await res.json();
console.log(data.data.actor.account.nrql.results);

Common Automation

  • Entity search — find all entities with a tag
  • Tagging — add team tags in bulk
  • Dashboards — export and import JSON
  • Alerts — create policies and conditions
  • Change tracking — record deployments from CI
  • Reports — weekly SLA or error reports emailed to stakeholders

Example: Entity Search

{
  actor {
    entitySearch(query: "domain = 'APM' AND tags.team = 'payments'") {
      results { entities { name guid } }
    }
  }
}

Tips

  • Store keys in secret managers
  • Paginate large results with cursors
  • Prefer Terraform for long-lived configuration; use NerdGraph for scripts and integrations

If you're repeating the same clicks in New Relic every week, NerdGraph can do it for you.

Arivanandhan Chitheshwaran