Authorization

To use the Yandex Metrica API, you need to get an authorization token through the Yandex OAuth server. The token must be passed for each method in the HTTP Authorization header.

GET /management/v1/counters HTTP/1.1
Host: api-.yandex.net
Authorization: OAuth 05dd3dd84ff948fdae2bc4fb91f13e22bb1f289ceef0037
Content-Type: application/x-yametrika+json
Content-Length: 123

If an API method is called without a token, or the request includes an invalid token, the server returns the HTTP status 401 Unauthorized.

Note. Authorization tokens must be stored securely and not given to third parties.

Obtaining the OAuth token

Attention. If you work with the Yandex Metrica API directly from your browser, use the instructions.
To get an authorization 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 a set of access permissions for your app. Access types:

      • metrika:read: Getting statistics, reading parameters of custom and trusted tags, getting a list of tags.
      • metrika:write: Creating tags, changing parameters of custom and trusted tags, uploading any data.
      • metrika:expenses: Uploading expenses to tags.
      • metrika:user_params: Uploading user parameters to tags.
      • metrika:offline_data: Uploading offline data (CRM data, offline conversions, calls) to tags.
      Note. The metrika:expenses, metrika:user_params, and metrika:offline_data access permissions are optional if you use metrika:write.
  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.