---
title: Application error rate example (v2)
source: https://docs.newrelic.com/docs/apis/rest-api-v2/application-examples-v2/application-error-rate-example-v2
---

This is an example of how to use the New Relic Data API (v2) to get your application's average error rate over a specific time period. This value appears as a percentage above the [Error rate chart](#avg-error-image) on your [APM **Summary** page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page).

> #### ⚠️ IMPORTANT
>
> While the examples utilize New Relic's REST API v2, we recommend using [NRQL functions](https://docs.newrelic.com/docs/nrql/get-started/introduction-nrql-new-relics-query-language/) for executing metric timeslice queries. Each API value can be mapped to an equivalent NRQL function. To learn how to create NRQL queries based on these API examples, refer to our [documentation](https://docs.newrelic.com/docs/apis/rest-api-v2/migrate-to-nrql/).

To use the API, you need:

-   An [API key](https://docs.newrelic.com/docs/apis/rest-api-v2/getting-started/introduction-new-relic-rest-api-v2#api_key).
-   Your New Relic application ID (from the URL that your browser shows from the APM user interface, or from the [API Explorer user interface](https://docs.newrelic.com/docs/apis/api-explorer-examples-metric-data#app_id))

## Formula [#avg-error-time-formula]

The average percentage appears above the **Error rate** chart on your app's [**Summary** page](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page). New Relic uses this formula to calculate it:

```
Application Error Rate = 100 * Errors/all:error_count / (HttpDispatcher:call_count + OtherTransaction/all:call_count)
```

## API commands [#avg-error-time-commands]

To obtain the [metric timeslice](https://docs.newrelic.com/docs/data-analysis/metrics/analyze-your-metrics/data-collection-metric-timeslice-event-data#timeslice-data) values, use the following three commands. This example uses the same time period for each command, and they are all summarized.

To obtain the **error count:**

**Call to obtain error count**

````sh
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
    -H "Api-Key:$API_KEY" -i \
    -d 'names[]=Errors/all&values[]=error_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
```

````

**Example output from error count call**

````json
{
  "metric_data": {
    "from": "2014-04-01T00:00:00+00:00",
    "metrics": [
      {
        "name": "Errors/all",
        "timeslices": [
          {
            "from": "2014-04-01T00:35:00+00:00",
            "to": "2014-04-01T23:35:00+00:00",
            "values": {
              "error_count": 5
            }
          }
        ]
      }
    ],
    "metrics_found": [
      "Errors/all"
    ],
    "metrics_not_found": [],
    "to": "2014-04-01T23:35:00+00:00"
  }
}
```

````

To get the **HttpDispatcher call count** (web application):

**Call to obtain HttpDispatcher call count**

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

````

**Example output from HttpDispatcher call count call**

````json
{
  "metric_data": {
    "from": "2014-04-01T00:00:00+00:00",
    "metrics": [
      {
        "name": "HttpDispatcher",
        "timeslices": [
          {
            "from": "2014-04-01T00:35:00+00:00",
            "to": "2014-04-01T23:35:00+00:00",
            "values": {
              "call_count": 19608
            }
          }
        ]
      }
    ],
    "metrics_found": [
      "HttpDispatcher"
    ],
    "metrics_not_found": [],
    "to": "2014-04-01T23:35:00+00:00"
  }
}
```

````

To get the **OtherTransaction call count** (non-web app):

**Call to obtain OtherTransaction call count**

````sh
curl -X GET "https://api.newrelic.com/v2/applications/$APP_ID/metrics/data.xml" \
    -H "Api-Key:$API_KEY" -i \
    -d 'names[]=OtherTransaction/all&values[]=call_count&from=2014-04-01T00:00:00+00:00&to=2014-04-01T23:35:00+00:00&summarize=true'
```

````

**Example output from OtherTransaction call count call**

````json
{
  "metric_data": {
    "from": "2014-04-01T00:00:00+00:00",
    "metrics": [
      {
        "name": "OtherTransaction/all",
        "timeslices": [
          {
            "from": "2014-04-01T00:35:00+00:00",
            "to": "2014-04-01T23:35:00+00:00",
            "values": {
              "call_count": 4
            }
          }
        ]
      }
    ],
    "metrics_found": [
      "OtherTransaction/all"
    ],
    "metrics_not_found": [],
    "to": "2014-04-01T23:35:00+00:00"
  }
}
```

````
