Introduction to New Relic REST API (v2)

The New Relic REST API is a programming interface that allows you to access data directly from New Relic products. The primary use is to extract your APM data via GET requests; however, you can also use PUT requests to configure some features, and use DELETE requests to remove non-reporting application instances.

Access to metric timeslice data depends on your subscription level. Summary data is the only data available for free New Relic accounts.

Video tutorial

For an overview of New Relic's REST API, watch this video.

 

[video link] For an overview of the REST API, watch this video (approximately 6 minutes). View more videos and tutorials at learn.newrelic.com.

Setup

Owner or Admins

To use the REST API you must activate API access and generate your API keys from your account settings. You can then acquire data via the command line. The command structure follows this template:

curl  -X GET <URL> -H "X-api-key:${API_KEY}" -d '<PAYLOAD>'

The GET command could also be a POST or DELETE, depending on the query intent.

The examples in New Relic documentation use cURL as a common command line tool to pull metric timeslice data from the REST API. However, you can use any method to make your REST requests. The curl commands include target URLs, header information, and data which are relevant for any request mechanism.

URL

The API calls require a URL to specify the location from which the data will be accessed. You must replace the placeholder <URL> with the appropriate URL which will change depending on the type of data being requested. In general the URL follows this template:

https://api.newrelic.com/v2/applications/${APPID}/metrics/data.json

The ${APPID} specifies the exact application or product for which the data is being requested. The information following this parameter will vary depending on the data request.

You can retrieve XML data instead of JSON by replacing .json with .xml.

API key ${API_KEY}

New Relic API calls require an API key in the call header. The API key uniquely identifies your account and authorizes access to your account data. New Relic borrows the placeholder ${API_KEY} from Unix shell programming; be sure to replace ${API_KEY} with an API key from your New Relic account.

Query details (PAYLOAD)

The <PAYLOAD> contains the query details, which define:

  • The metric name you want to query and the value you want to retrieve
  • The defined time range for retrieving metrics
  • (Optional): The average of the metric timeslice data by using summarize

Examples

See the following documents for example API use cases:

  • APM examples (how to retrieve metric timeslice data from New Relic APM)
  • Browser examples (how to retrieve metric timeslice data from New Relic Browser)
  • Labels examples (how to retrieve information about your labels and categories for apps)
  • Plugin examples (how to retrieve information and metric timeslice data about plugins from New Relic Plugin Central)

For alerting, see the appropriate documents for your alerting system:

For more help

Additional documentation resources include:

  • Requirements (required elements of a query, explanation of the output data, and how to customize the output)
  • API Explorer (how to use the API Explorer, a graphical interface for API queries)

If you need additional help, get support at support.newrelic.com.