Specify a time range (v2)

You can specify a time range for the data to be returned in a New Relic REST API call. You can also request to return an average over the time range instead of the series of values returned by default.

Change the default 30 minute time range

The default time range for an API call is the last 30 minutes. To modify the time range, include from= and optional to= values. (To end the time range at the current time, omit to=.)

Data availability is subject to the data retention policy for your subscription level.

Example:

curl -X GET "https://api.newrelic.com/v2/applications/${APPID}/metrics/data.json" \ -H "X-Api-Key:${APIKEY}" -i \ -d 'names[]=Agent/MetricsReported/count&from=2014-08-11T14:42:00+00:00&to=2014-08-11T15:12:00+00:00'

The time period returned for each data point depends on the time range you specify. To modify the time period, include the period parameter in your query.

If you are using the New Relic REST API Explorer (v2), you can use the diamond icon-api-diamond icon to select time ranges. If you have an EU region account, the above URL begins with https://api.eu.newrelic.com.

Offset UTC

By default the API time input uses Universal Time Coordinated (UTC). To offset the UTC, use plus or minus 00:00 in your API call. This allows you to input times in a different time zone; however, this does not modify the output times, which are always UTC.

  • For time zones east of UTC, use a minus sign (-). This symbol has no special meaning in HTTP or HTTPS requests.
  • For time zones west of UTC, use the encoded value %2B to indicate a plus sign (+).
  • If you have an EU region account, the following URLs begin with https://api.eu.newrelic.com.

This API call shows a time zone east of UTC by 2 hours (-02:00)
curl -X GET "https://api.newrelic.com/v2/applications/${APPID}/metrics/data.json" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d 'names[]=Agent/MetricsReported/count&from=2014-08-11T14:42:00-02:00&to=2014-08-11T15:12:00-02:00'
This API call shows a time zone west of UTC by +8 hours (%2B08:00)
curl -X GET "https://api.newrelic.com/v2/applications/${APPID}/metrics/data.json" \
     -H "X-Api-Key:${APIKEY}" -i \
     -d 'names[]=Agent/MetricsReported/count&from=2014-08-11T14:42:00%2B08:00&to=2014-08-11T15:12:00%2B08:00

For more help

Additional documentation resources include:

Recommendations for learning more: