Calling the Yandex.Metrica API from the browser

You can access all Yandex.Metrica API sections directly from the browser. You can send only read requests (GET) when accessing the API this way.

To work with the API, you need to get an access token from the Yandex OAuth server and pass it in the Authorization HTTP header of every API request. To get a token, first register your application.

When registering, choose the “Access to statistics and ability to view all counter settings (metrika:read)” type of access rights.

Attention. Don't choose “Ability to create counters and configure all counter settings (metrika:write)” because you can't send data modification requests (POST, PUT and DELETE) directly from the browser.

In addition, the token could be downloaded from the browser and used for accessing the API without your knowledge.

If you already have an access token with read and write permissions, get a separate token for accessing the API from the browser. This token should be used only for getting statistics and reading tag parameters.

Example of using the token in a request

This example uses the fetch method to access the Yandex.Metrica server:

  '', {
    headers: {
      "Authorization": "OAuth 05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037"
  .then(r => r.json())
  .then(metrikaApiJSON => {

where 05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037 is the access token.