---
title: How to use our REST API (v2)
source: https://docs.newrelic.com/docs/apis/rest-api-v2/get-started/introduction-new-relic-rest-api-v2
---

> #### ⚠️ FEATURE AVAILABILITY
>
> This feature isn't available in all regions. Refer to the [data center and regional availability](https://docs.newrelic.com/docs/accounts/accounts-billing/account-setup/choose-your-data-center#feature-limitations-by-region) page to check if it's supported in your region and explore alternative solutions.

New Relic's REST API lets you retrieve data from and push data to New Relic tools, as well as to configure features and perform delete operations. You can also use the [API Explorer](https://docs.newrelic.com/docs/apis/rest-api-v2/api-explorer-v2/getting-started-new-relics-api-explorer) to understand the data available to you via the REST API, to obtain curl commands, and to see JSON responses.

## Setup

The REST API command structure follows this template:

```
curl -X GET <a href="#appid"><var>URL</var></a> -H "Api-Key:<a href="#api_key"><var>$API_KEY</var></a>" -d '<a href="#payload"><var>PAYLOAD</var></a>'
```

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

To understand the placeholders, keep reading.

> #### 💡 TIP
>
> Our examples 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 [#appid]

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/$APP_ID/metrics/data.json
```

The [$APP_ID](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/finding-product-id) 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.

If you have an [EU region account](https://docs.newrelic.com/docs/using-new-relic/welcome-new-relic/getting-started/introduction-eu-region-data-center), the URL is:

```
api.eu.newrelic.com/v2/applications/$APP_ID/metrics/data.json
```

> #### 💡 TIP
>
> You can retrieve XML data instead of JSON by replacing `.json` with `.xml`.

## API key `$API_KEY` [#api_key]

New Relic API requires a [user API key](https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#user-api-key): The user key is also used for our [NerdGraph API](https://docs.newrelic.com/docs/apis/nerdgraph/get-started/introduction-new-relic-nerdgraph).

In our REST API examples, we borrow the API key placeholder `$API_KEY` from Unix shell programming. Be sure to replace that and other user-specific variables when forming calls.

## Query details (PAYLOAD) [#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](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/specifying-time-range-v2) for retrieving metrics
-   (Optional): The average of the metric timeslice data by using [summarize](https://docs.newrelic.com/docs/apis/rest-api-v2/requirements/calculating-average-metric-values-summarize)

## Examples

See the following docs for example REST API use cases:

-   [APM examples](https://docs.newrelic.com/docs/apis/rest-api-v2/application-examples-v2) (how to retrieve metric timeslice data from APM).
-   [Browser examples](https://docs.newrelic.com/docs/apis/rest-api-v2/browser-examples-v2) (how to retrieve metric timeslice data from browser monitoring). The REST API only returns the Lite browser agent script. For more information, [see this table comparing Lite, Pro, and Pro+SPA types](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent).
-   [Infrastructure alert examples](https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/infrastructure-alert-conditions/rest-api-calls-new-relic-infrastructure-alerts)
-   [Alerts examples](https://docs.newrelic.com/docs/alerts/new-relic-alerts/rest-api-alerts) (create alert conditions and configure notification channels, and more).
