Authenticating with an API key

There are three methods available to use the API key along with the above Public API format URL to get access to your application's data, in recommended order:

  1. Custom header: you can use the custom header X-Api-Key with your API key
  2. Basic authentication: you can provide the API key as either the username or password for basic authentication. If you provide both fields, the API requires that API key be in the username.
  3. Query parameter: The API supports the parameter &api_key which enables you to pass the API key without specifying any headers.

An example showing the use of the Application ID ({app-id}) and API key in the header when using cURL is:

curl "https://api.applicationinsights.io/{api-version}/{app-id}/{query-path}?[query-parameters]
-H "X-Api-Key: {api-key}"

You can test this using a demo application by executing the following cURL which will return the total number of requests in the last 24 hours:

curl "https://api.applicationinsights.io/v1/apps/DEMO_APP/metrics/requests/count"
-H "X-Api-Key: DEMO_KEY"

which returns a status code 200 (Success) and the payload:

{
  "value": {
    "start": "2016-04-01T08:21:33.221Z",
    "end": "2016-04-01T20:21:33.221Z",
    "requests/count": {
      "sum": 22778
    }
  }
}

Viewing your app's data in the API Explorer

You can try out the API Explorer with your own application by copying your app's Application ID and API key from the portal as follows:

Trying the API Explorer with your application.

Authentication errors

If either the Application ID or the API key are incorrect, the API service will return a 403 (Forbidden) error.