Managing the option and tokens
Enabling the option via the API
curl -X PUT 'https://api-metrica.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
To check if the feature is enabled, send a request:
curl -X GET 'https://api-metrica.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):
{
"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
Note
In the response, you will see active tokens regardless of the status of the measurement_enabled
flag.
Request
curl -X GET 'https://api-metrica.yandex.net/management/v1/counter/{counter_id}?field=measurement_tokens'
-H 'Authorization: OAuth <access_token>'
Response
{
"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
You can generate additional tokens using the request:
curl -X GET 'https://api-metrica.yandex.net/management/v1/counter/{counterId}/measurement/generate'
-H 'Authorization: OAuth <access_token>'
In response, you will get a new token:
{
"response": "XXXXb007-XxDD-4700-9002-XXXX0eae000b"
}
Warning
The maximum number of active tokens per tag is 5. If you try to generate more, you will get the 400
response:
{
"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]"
}
Deleting a token
You can delete a token using the request:
curl -X POST 'https://api-metrica.yandex.net/management/v1/counter/{counterId}/measurement/delete?token={token}'
-H 'Authorization: OAuth <access_token>'
Note
You need to specify all the obtained tokens in the ms
(Measurement Secret) parameter when sending data.
Was the article helpful?
Previous
Next