Calling the Yandex Metrica API from the browser

You can access all sections of the Yandex Metrica API directly from your browser. With this method, you can:
  • Access only the Yandex Metrica address hosted on the .net domain.
  • Send read-only (GET) requests.
To work with the API from your browser, you need an authorization token. To get a token:
  1. Create an app and fill in the fields:
    • Name: Any name of your choice.
    • Service icon: Optional.
    • Platforms: Select Web services.
    • redirect URI: Specify https://oauth.yandex.com/verification_code.
    • Data access: Specify metrika:read.
  2. Click Create app and copy its ClientID (next to the ID, click ).
  3. Add the copied ClientID to the link as follows
    https://oauth.yandex.com/authorize?response_type=token&client_id=<app ID>
  4. Follow the link and copy your authorization token on the page that opens.
Attention. Do not select metrika:write, because you cannot send requests to modify data (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. We recommend that you store your authorization token securely and not give it to third parties.

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

In the example, the fetch method is used to communicate with the Yandex Metrica server:

fetch(
  'https://api-.yandex.net/stat/v1/data?preset=sources_summary&id=44147844', {
    headers: {
      "Authorization": "OAuth 05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037"
    } 
  })
  .then(r => r.json())
  .then(metrikaApiJSON => {
    ...
  })

where 05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037 is the authorization token.