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-metrica.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 an OAuth token
To get an authorization token:
- Create an app and fill in the fields:
- Name: Any name of your choice.
- Service icon: Optional.
- Platforms: Select Web services.
- Redirect URI: Enter https://oauth.yandex.com/verification_code.
Data access: Specify a set of accesses for your app. Types of accesses:
- metrika:read: Getting statistics, reading parameters of your own and trusted tags, getting a list of tags.
- metrika:write: Creating tags, changing parameters of your own 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. metrika:expenses, metrika:user_params, and metrika:offline_data accesses are optional if metrika:write is used.
- Click Create app and copy its ClientID (next to the ID, click ).
- Add the copied ClientID to the link as follows
https://oauth.yandex.com/authorize?response_type=token&client_id=<app ID>
- Follow the link and copy your authorization token on the page that opens.