---
metadata:
  - name: generator
    content: Diplodoc Platform v5.48.2
alternate:
  - https://yandex.com/dev/metrika/en/intro/authorization.md
  - https://yandex.com/dev/metrika/ru/intro/authorization.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/metrika/en/llms.txt

# Authorization

To use the Yandex Metrica API, you need to get an [authorization token](https://yandex.com/dev/id/doc/en/concepts/ya-oauth-intro) 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-metrika.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 info %}

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

{% endnote %}

## Obtaining an OAuth token {#get-oauth-token}

To get an authorization token:

<!-- source: en/_includes/oauth.md -->
1. [Create an app](https://oauth.yandex.com/?dialog=create-client-entry) and select **For API access or debugging**. 

1. Fill in the information:
    - **Name**: Any name of your choice.
    - **Email**: Specify your preferred contact email.
    - **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.

        **metrika:expenses**, **metrika:user_params**, and **metrika:offline_data** accesses are optional if **metrika:write** is used.

    {% note info %}

    If you're using porg usernames (organization usernames), add **passport:business** to the access permissions. This is required to issue a token from the organization.

    {% endnote %}

1. Click **Create app** and copy its ClientID (next to the ID, click <svg width="24" height="24" fill="none" viewBox="0 0 24 24" aria-hidden="true" focusable="false" role="img" class="svg-icon"><path fill="currentColor" d="M8 5h7.795c1.115 0 1.519.116 1.926.334s.727.538.945.945S19 7.09 19 8.205V16a1 1 0 1 0 2 0V8.128c0-1.783-.186-2.43-.534-3.082a3.64 3.64 0 0 0-1.512-1.512C18.302 3.186 17.655 3 15.872 3H8a1 1 0 0 0 0 2"/><path fill="currentColor" fill-rule="evenodd" d="M6.205 7c-.882 0-1.393.049-1.926.334a2.27 2.27 0 0 0-.945.945C3.049 8.812 3 9.323 3 10.205v7.59c0 .882.049 1.392.334 1.926.218.407.538.727.945.945.533.285 1.044.334 1.926.334h7.59c.882 0 1.393-.049 1.926-.334.407-.218.727-.538.945-.945.285-.534.334-1.044.334-1.926v-7.59c0-.882-.049-1.393-.334-1.926a2.27 2.27 0 0 0-.945-.945C15.187 7.049 14.677 7 13.795 7zm-.983 2.098a.5.5 0 0 1 .197-.062A6 6 0 0 1 6.205 9h7.59c.423 0 .648.015.786.036a.5.5 0 0 1 .197.062.3.3 0 0 1 .124.124.5.5 0 0 1 .062.197c.021.138.036.363.036.786v7.59c0 .423-.015.648-.036.786a.5.5 0 0 1-.062.197.3.3 0 0 1-.124.125.5.5 0 0 1-.197.06c-.138.022-.363.037-.786.037h-7.59a6 6 0 0 1-.786-.036.5.5 0 0 1-.197-.061.3.3 0 0 1-.124-.125.5.5 0 0 1-.062-.197A6 6 0 0 1 5 17.795v-7.59c0-.423.015-.648.036-.786a.5.5 0 0 1 .062-.197.3.3 0 0 1 .124-.124" clip-rule="evenodd"/></svg>).

1. Add the copied ClientID to the link as follows

    ```http translate=no
    https://oauth.yandex.com/authorize?response_type=token&client_id=<application_id>
    ```

1. Follow the link and copy your authorization token on the page that opens.
<!-- endsource: en/_includes/oauth.md -->

## Troubleshooting {#troubles}

<!-- source: en/_includes/oauth.md -->
{% cut "Error 403 (Access is denied) after obtaining a token" %}

Possible reasons:

**App-side**

- The app doesn't have access to Yandex Metrica. To read tag data (for example, to generate reports or view tag information), your app requires `metrika:read` access. To manage tags (for example, to upload offline data or edit tags and segments), your app requires `metrika:write` access.

**Token-side**

- The token is invalid. The token expired or the authorization password for the associated account was changed. Issue another token.

- The token was issued for another account. It may have been issued for a username that doesn't have access to the Yandex Metrica tag.

     {% note warning %}

     The token owner is not the app owner but the account that you used to make the GET request to obtain the token.

     {% endnote %}

- The token was created for another app. The GET request to obtain the token included an incorrect `client_id` value or a typo that resulted in the token being issued for an app that doesn't have `metrika:read` or `metrika:write` access to Yandex Metrica.

**Yandex Metrica-side**

- The token owner doesn't have access to the tag that you're attempting to access via the API. [Learn more](https://yandex.com/support/metrica/general/access.html) about the types of tag access. The Management API requires owner, guest view, or guest write access.

**API request-side**

- The token is read incorrectly or not at all due to incorrect authorization parameters in the API call code.

{% endcut %}

{% cut "Error 401 (unauthorized) after obtaining a token" %}

Possible reasons:

1. The authorization parameters in the request header are incorrect.
2. The header is missing authorization parameters.

{% endcut %}
<!-- endsource: en/_includes/oauth.md -->
