---
title: API examples for SLA reports
source: https://docs.newrelic.com/docs/apm/reports/api-examples-sla-reports
---

New Relic stores SLA data forever for [eligible accounts](http://newrelic.com/application-monitoring/pricing), so you can use the [New Relic REST API](https://docs.newrelic.com/docs/apm/apis/requirements/new-relic-rest-api-v2-getting-started) to generate service level agreement reports over any time period. For example, you can create SLA reports going back more than 12 days, weeks, or months.

> #### 💡 TIP
>
> Access to this feature depends on your [subscription level](https://newrelic.com/pricing).

## Browser metrics for SLAs [#browser-metrics]

Browser metrics for the **End user** [tier](https://docs.newrelic.com/docs/accounts-partnerships/education/getting-started-new-relic/glossary#tier) are available only if you have [installed the browser monitoring agent](https://docs.newrelic.com/docs/browser/new-relic-browser/getting-started/browser-settings).

| **Browser (End user tier)** | **SLA metric name:value (and formula)**           |
| --------------------------- | ------------------------------------------------- |
| Page Views thousands        | EndUser : call_count                              |
| Load time sec               | EndUser : average_response_time                   |
| Apdex                       | EndUser/Apdex : score                             |
| % Satisfied                 | EndUser/Apdex : s divided by EndUser : call_count |
| % Tolerating                | EndUser/Apdex : t divided by Enduser : call_count |
| % Frustrated                | EndUser/Apdex : f divided by Enduser : call_count |

## App server metrics for SLAs [#app-metrics]

Here are the SLA metrics for application servers.

| **App server**    | **SLA metric name:value (and formula)**                     |
| ----------------- | ----------------------------------------------------------- |
| Requests millions | HttpDispatcher : call_count (scaled appropriately)          |
| Resp. time ms     | HttpDispatcher : average_response_time (multiplied by 1000) |
| Apdex             | Apdex : score                                               |
| % Satisfied       | Apdex : s divided by Apdex : count                          |
| % Tolerating      | Apdex : t divided by Apdex : count                          |
| % Frustrated      | Apdex : f divided by Apdex : count                          |

## Tips for collecting metrics [#tips]

Here are some tips for planning which metrics to collect.

| **SLA tips**        | **Comments**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Requirements        | When using the cURL command examples, be sure to replace the placeholder text with your [account ID](https://docs.newrelic.com/docs/accounts-partnerships/accounts/account-setup/account-id), an [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key), and the [application ID](https://docs.newrelic.com/docs/apm/apis/requirements/finding-product-id).                                                                                                                                        |
| Time ranges         | You are not limited to standard day, week, or month time ranges. For example, you can [extract metric data](https://docs.newrelic.com/docs/apm/apis/requirements/extracting-metric-data) for a "holiday weekend" from 12/23 to 12/26 or "the 20 minutes after our site had problems" or whatever other period interests you.                                                                                                                                                                                                                                      |
| UTC XML time format | You must specify the time in UTC XML format, so be sure to adjust for your [time zone compared to UTC](https://docs.newrelic.com/docs/apm/apis/requirements/specifying-time-range-api-v2). For example, New Relic starts at 16:00:00 on the day before the selected data, since New Relic headquarters are in UTC-8.                                                                                                                                                                                                                                              |
| Summary reports     | When requesting metrics to use with [summary reports](https://docs.newrelic.com/docs/apm/apis/requirements/calculating-average-metric-values-summarize), include the query string parameter `summarize=true` (v2) or `summary=1` (v1) as shown in the examples.                                                                                                                                                                                                                                                                                                   |
| Scaled statistics   | Your report has some statistics that are scaled in the [SLA reports in New Relic's user interface](https://docs.newrelic.com/docs/apm/reports/service-level-agreements/sla-reports). New Relic changes the scale of page views in your report to show small numbers. Depending on your traffic, typically it might be displayed in thousands, millions, or billions. Recommendation: To avoid a string of zeros, divide this number appropriately for your own purposes.                                                                                          |
| End user statistics | End user statistics will reflect only the calls in which the agent gathered browser data. For example, end user stats may not appear in situations such as: - Browser types - Clients (they might have disabled the JavaScript agent, or blocked traffic to New Relic sites for JavaScript code's location - Transactions not in one of those categories, in case the page load did not complete for any reason This is why there are fewer (sometimes many fewer) page views in the **End User** (browser) data section than in the **App server** data section. |

## Examples

The following sections contain code examples to acquire the data for values described above for the Daily (24hr) SLA statistics in the default GMT/UTC time zone. Adjust the `from=` and `to=` for your [time range](https://docs.newrelic.com/docs/apm/apis/requirements/specifying-time-range-api-v2) as desired.

> #### ⚠️ IMPORTANT
>
> Although the examples include both New Relic's REST API v2 and NerdGraph, we recommend using [NerdGraph](https://docs.newrelic.com/docs/apis/nerdgraph/examples/nerdgraph-slm) for querying New Relic data, retrieving account information, and configuring features. To explore its capabilities, check [the NerdGraph tutorials](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph/#tutorials).

## REST API v2 commands [#examples_v2]

**Browser load time and page view count (v2)**

To obtain the browser (EndUser/RUM) load time and page view count for v2, from the command line, type:

````bash
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml"\
    -H "Api-Key:$API_KEY" -i  \
    -d "names[]=EndUser&values[]=call_count&values[]=average_response_time&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true"
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml?names[]=EndUser&values[]=call_count&values[]=average_response_time&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["api-key"] = "$API_KEY"
  curl.header_in_body=true
end
puts response.body_str
```

````

**App response time and request count (v2)**

To obtain the Application response time and request count for v2, from the command line, type:

````bash
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
     -H "Api-Key:$API_KEY" -i \
     -d "names[]=HttpDispatcher&values[]=average_response_time&values[]=call_count&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true"
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml?names[]=HttpDispatcher&values[]=average_response_time&values[]=call_count&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["api-key"] = "$API_KEY"
  curl.header_in_body=true
end
puts response.body_str
```

````

**Apdex SLA data (v2)**

To obtain the Apdex related data for v2, from the command line, type:

````bash
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
     -H "Api-Key:$API_KEY" -i \
     -d 'names[]=Apdex&names[]=EndUser/Apdex&from=2014-06-09T00:00:00+00:00&to=2014-06-09T23:00:00+00:00&summarize=true'
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.http_get("https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml?names[]=EndUser/Apdex&from=2012-01-01T00:00:00+00:00&to=2012-01-08T00:00:00+00:00&summarize=true") do |curl|
  curl.headers["api-key"] = "$API_KEY"
  curl.header_in_body=true
end
puts response.body_str
```

````

## NerdGraph API commands [#nerdgraph-commands]

**App average response time (NerdGraph)**

To obtain the Application average response time, execute the following query in the [NerdGraph API Explorer](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/nerdgraph-explorer/):

````graphql
SELECT average(apm.service.transaction.duration) as duration 
FROM WHERE (entity.guid = 'Nzc5ODIwfEFQTXxBUFBMSUNBVElPTnwzMjMzNDE2') 
FACET weekOf(timestamp) 
LIMIT MAX 
SINCE '2025-02-03' 
TIMESERIES 
```

````

**App request count (NerdGraph)**

To obtain the Application request count, execute the following query in the [NerdGraph API Explorer](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/nerdgraph-explorer/):

````graphql
SELECT ((count(apm.service.transaction.duration))/1000) 
FROM WHERE (entity.guid = 'Nzc5ODIwfEFQTXxBUFBMSUNBVElPTnwzMjMzNDE2') 
FACET weekOf(timestamp) 
LIMIT MAX 
SINCE '2025-02-03' 
TIMESERIES 
```

````

**Apdex SLA data (NerdGraph)**

To obtain the Apdex related data, execute the following query in the [NerdGraph API Explorer](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/nerdgraph-explorer/):

````graphql
SELECT apdex(apm.service.apdex) 
FROM Metric 
WHERE (entity.guid = 'Nzc5ODIwfEFQTXxBUFBMSUNBVElPTnwzMjMzNDE2') 
FACET weekOf(timestamp) 
LIMIT MAX 
SINCE '2025-02-03' 
TIMESERIES
```

````

## REST API v1 commands (deprecated) [#examples_v1]

REST API v1 is deprecated.

**Browser load time and page view count (v1)**

To obtain the browser (EndUser/RUM) load time and page view count for v1, from the command line, type:

````bash
curl -gH "api-key:$API_KEY" "https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=EndUser&field=call_count&field=average_response_time&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=EndUser&field=call_count&field=average_response_time&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["api-key"] = "$API_KEY"
end
puts response.body_str
```

````

**App response time and request count (v1)**

To obtain the Application response time and request count for v1, from the command line, type:

````bash
curl -gH "api-key:$API_KEY" "https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=HttpDispatcher&field=average_response_time&field=call_count&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=HttpDispatcher&field=average_response_time&field=call_count&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["api-key"] = "$API_KEY"
end
puts response.body_str
```

````

**Apdex SLA data (v1)**

To obtain the Apdex related data for v1, from the command line, type:

````bash
curl -gH "api-key:$API_KEY" "https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=Apdex&metrics[]=EndUser/Apdex&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z"
```

In Ruby:

```ruby
require 'rubygems'
require 'curb'

response = Curl::Easy.perform("https://api.newrelic.com/api/v1/accounts/$ACCOUNT_ID/applications/$APP_ID/data.xml?metrics[]=Apdex&metrics[]=EndUser/Apdex&summary=1&begin=2012-01-01T00:00:00Z&end=2012-01-08T00:00:00Z") do |curl|
  curl.headers["api-key"] = "$API_KEY"
end
puts response.body_str
```

````

## Analyze your data [#insights]

APM includes several reports in the user interface. To gather, analyze, and visualize data about your software in other formats, use [dashboards](https://docs.newrelic.com/docs/query-your-data/explore-query-data/dashboards/introduction-dashboards/).
