---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com/dev/metrika/en/intro/quick-start.md
  - https://yandex.com/dev/metrika/ru/intro/quick-start.md
  - href: en/intro/quick-start.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/metrika/en/llms.txt

# Quick start

## Step 1. Get an OAuth token {#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 ![](../../_images/copy.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 -->

## Step 2. Choose an API to work with {#api}

Yandex Metrica offers three primary APIs:

* [Management API](https://yandex.com/dev/metrika/en/management/index.md). This API allows you to create and edit tags, goals, filters, and other objects.
* [Data import API](https://yandex.com/dev/metrika/en/data-import/index.md). With this API, you can import customer and order data from a CRM, as well as information about calls, offline conversions, and user parameters.
* [Reports API](https://yandex.com/dev/metrika/en/stat/index.md). You can use this API to retrieve site traffic information and other data. Generate reports, including segmented and parameterized reports.
* [Logs API](https://yandex.com/dev/metrika/en/logs/index.md). Through this API, you can access non-aggregated data collected by Yandex Metrica. Choose this API if you process statistical data on your own or use it to tackle specific analytical challenges.

## Step 3. Use the API to edit an object {#edit}

To demonstrate, let's create a goal using the Management API:

1. First, select a tag for which you want to create the goal. To do this, call the [GET https://api-metrika.yandex.net/management/v1/counters](https://yandex.com/dev/metrika/en/management/openapi/counter/counters.md) method and select the required tag from the list.

   **Request:**
   ```http translate=no
   curl -i -X GET 'https://api-metrika.yandex.net/management/v1/counters' \
   -H 'Authorization: OAuth 05dd3dd8...'
   ```

   **Response:**
   ```json translate=no
   {
     "rows": 2,
     "counters": [
       {
         "id": 880000,
         "status": "Active",
         "owner_login": "example-developer",
         "code_status": "CS_ERR_UNKNOWN",
         "activity_status": "low",
         "name": "counter_option test example-developer",
         "type": "simple",
         "favorite": 0,
         "hide_address": 0,
         "pro": 0,
         "permission": "view",
         "webvisor": {
           "arch_enabled": 0,
           "arch_type": "none",
           "load_player_type": "proxy",
           "wv_version": 2,
           "allow_wv2": true,
           "notify_wv2": false,
           "wv_forms": 1
         },
         "code_options": {
           "async": 1,
           "informer": {
             "enabled": 0,
             "type": "ext",
             "size": 3,
             "indicator": "pageviews",
             "color_start": "FFFFFFFF",
             "color_end": "EFEFEFFF",
             "color_text": 0,
             "color_arrow": 1
           },
           "visor": 0,
           "track_hash": 0,
           "xml_site": 0,
           "clickmap": 1,
           "in_one_line": 0,
           "ecommerce": 0,
           "alternative_cdn": 0,
           "ecommerce_object": "dataLayer",
           "ytm": false
         },
         "create_time": "2022-03-25T15:59:52+03:00",
         "time_zone_name": "Europe/Moscow",
         "time_zone_offset": 180,
         "partner_id": 0,
         "site": "example-developer.ru",
         "site2": {
           "site": "example-developer.ru",
           "domain": "example-developer.ru"
         },
         "gdpr_agreement_accepted": 0,
         "delete_guest_allowed": 1
       },
       {
         "id": 87686941,
         "status": "Active",
         "owner_login": "example-manager",
         "code_status": "CS_ERR_UNKNOWN",
         "activity_status": "low",
         "name": "example-manager_1",
         "type": "simple",
         "favorite": 0,
         "hide_address": 0,
         "pro": 0,
         "permission": "edit",
         "webvisor": {
           "arch_enabled": 0,
           "arch_type": "none",
           "load_player_type": "proxy",
           "wv_version": 2,
           "allow_wv2": true,
           "notify_wv2": false,
           "wv_forms": 1
         },
         "code_options": {
           "async": 1,
           "informer": {
             "enabled": 0,
             "type": "ext",
             "size": 3,
             "indicator": "pageviews",
             "color_start": "FFFFFFFF",
             "color_end": "EFEFEFFF",
             "color_text": 0,
             "color_arrow": 1
           },
           "visor": 0,
           "track_hash": 0,
           "xml_site": 0,
           "clickmap": 1,
           "in_one_line": 0,
           "ecommerce": 0,
           "alternative_cdn": 0,
           "ecommerce_object": "dataLayer",
           "ytm": false
         },
         "create_time": "2022-03-02T16:06:27+03:00",
         "time_zone_name": "Europe/Moscow",
         "time_zone_offset": 180,
         "partner_id": 0,
         "site": "example-manager.ru",
         "site2": {
           "site": "example-manager.ru",
           "domain": "example-manager.ru"
         },
         "gdpr_agreement_accepted": 0,
         "delete_guest_allowed": 1
       }
     ]
   }
   ```

2. To create a goal, use the [POST https://api-metrika.yandex.net/management/v1/counter/{counterId}/goals](https://yandex.com/dev/metrika/en/management/openapi/goal/addGoal.md) method. Let's create a goal named [MessengerGoal](https://yandex.com/dev/metrika/en/management/openapi/goal/addGoal.md#messengergoal), which will track click-throughs to a specific messenger.

   **Request:**
   ```http translate=no
   curl -i -X POST 'https://api-metrika.yandex.net/management/v1/counter/XXX/goals' \
   -H 'Authorization: OAuth 05dd3dd8...' \
   -H 'Content-Type: application/json' \

   -d '{
          "goal": {
            "id": 0,
            "name": "MyMessengerGoal",
            "type": "messenger ",
            "conditions" : [{
              "type" :  "messenger", 
              "url" :  "whatsapp"
            }]
          }
    }'
   ```

   **Response:**
   ```http translate=no
   HTTP/1.1 200 OK

   {
      "goal": {
        "id": 222,
        "name": "MyMessengerGoal",
        "type": "messenger",
        "conditions" : [{
              "type" :  "messenger", 
              "url" :  "whatsapp"
            }]
        }
    }
   ```

