---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://yandex.com.tr/dev/metrika/en/data-import/manage-protocol.md
  - https://yandex.com.tr/dev/metrika/ru/data-import/manage-protocol.md
  - href: en/data-import/manage-protocol.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.tr/dev/metrika/en/llms.txt

# Managing the option and tokens

## Enabling the option via the API {#enable-option}

```http translate=no
curl -X PUT 'https://api-metrika.yandex.net/management/v1/counter/<counter_id>?field=counter_flags'
-H 'accept: application/json'
-H 'Authorization: OAuth <access_token>'
-H 'Content-Type: application/json'
-d '{
      "counter": {
        "counter_flags": {
          "measurement_enabled": true
        }
      }
    }'
```

## Checking if the flag is enabled {check-flag}

To check if the feature is enabled, send a request:

```http translate=no
curl -X GET 'https://api-metrika.yandex.net/management/v1/counter/<counter_id>?field=counter_flags'
-H 'Authorization: OAuth <access_token>'
```

The response will contain an enable flag (the `measurement_enabled` parameter):

```json translate=no
{
  "counter": {
    // ...
    "counter_flags": {
      "counter_id": <counter_id>,
      "use_in_benchmarks": true,
      "direct_allow_use_goals_without_access": true,
      "incognito": "disabled",
      "collect_first_party_data": true,
      "news_enabled_by_user": true,
      "news_enabled_by_classifier": true,
      "measurement_enabled": true
    },
  //...
  }
}
```

## Getting active tokens {get-tokens}

{% note info %}

In the response, you will see active tokens regardless of the status of the `measurement_enabled` flag.

{% endnote %}

**Request**

```http translate=no
curl -X GET 'https://api-metrika.yandex.net/management/v1/counter/{counter_id}?field=measurement_tokens'
-H 'Authorization: OAuth <access_token>'
```

**Response**

```json translate=no
{
  "counter": {
    // ...
    "measurement_tokens": [
      "196aXXXX-ebe0-XddX-XxDD-bXXXX7XXXX50",
      "XXX25XX4-XxDD-XXXX-a000-XXXXe3a4XXXX",
      "52cDDd3c-XXXX-4cef-XxDD-1709bXXXXa5a",
      "XXXXb007-XxDD-4700-9002-XXXX0eae000b"
    ]
  // ...
  }
}
```

## Generating additional tokens {#gen-tokens}

You can generate additional tokens using the request:

```http translate=no
curl -X GET 'https://api-metrika.yandex.net/management/v1/counter/{counterId}/measurement/generate'
-H 'Authorization: OAuth <access_token>'
```

In response, you will get a new token:

```json translate=no
{
  "response": "XXXXb007-XxDD-4700-9002-XXXX0eae000b"
}
```

{% note warning %}

The maximum number of active tokens per tag is 5. If you try to generate more, you will get the `400` response:

```json translate=no
{
  "errors": [
    {
      "error_type": "invalid_parameter",
      "message": "the limit of active tokens for the following counters has been reached: [counter_id]"
    }
  ],
  "code": 400,
  "message": "the limit of active tokens for the following counters has been reached: [counter_id]"
}
```

{% endnote %}

## Deleting a token {#delete-token}

You can delete a token using the request:

```http translate=no
curl -X POST 'https://api-metrika.yandex.net/management/v1/counter/{counterId}/measurement/delete?token={token}'
-H 'Authorization: OAuth <access_token>'
```

{% note info %}

You need to specify all the obtained tokens in the `ms` (Measurement Secret) parameter when [sending data](https://yandex.com.tr/dev/metrika/en/data-import/measurement-upload.md).

{% endnote %}
