Object IDs
To use dimensions and filters in the API, you need to know the IDs of specific values. For example, a request to filter users by region requires the ID of that region.
Generally, to obtain the ID of a specific object, you first need to make a general request to get a list of all objects.
The examples below show how to use IDs.
Region ID
Suppose you want to analyze traffic from Russian users and determine which search engines they come from. To do this, you need to know the region's ID.
First, make a request to get the IDs of all regions.
https://api-metrika.yandex.net/stat/v1/data/drilldown?ids=<counter_id>&dimensions=ym:s:regionCountry&metrics=ym:s:visits
In the response, find RU. Its id is 225.
Response with a list of countries and their IDs
"data": [
{
"dimension": {
"icon_id": "225",
"icon_type": "country",
"iso_name": "RU",
"id": "225",
"name": "Russia"
},
"metrics": [
13193
],
"expand": false
},
{
"dimension": {
"icon_id": "149",
"icon_type": "country",
"iso_name": "BY",
"id": "149",
"name": "Belarus"
},
"metrics": [
515
],
"expand": false
},
{
"dimension": {
"icon_id": "118",
"icon_type": "country",
"iso_name": "NL",
"id": "118",
"name": "Netherlands"
},
"metrics": [
435
],
"expand": false
},
{
"dimension": {
"icon_id": "159",
"icon_type": "country",
"iso_name": "KZ",
"id": "159",
"name": "Kazakhstan"
},
"metrics": [
374
],
"expand": false
},
{
"dimension": {
"icon_id": "96",
"icon_type": "country",
"iso_name": "DE",
"id": "96",
"name": "Germany"
},
"metrics": [
332
],
"expand": false
}
]
Now you can make the request to analyze the sources of search traffic for users in Russia by applying this filter: filters=(ym:s:regionCountry IN('225')).
https://api-metrika.yandex.net/stat/v1/data?ids=<counter_id>&metrics=ym:s:visits&dimensions=ym:s:<attribution>SourceEngine&filters=(ym:s:regionCountry IN('225'))
Source ID
Suppose you want to analyze traffic from search engines. To do this, you need to know the source ID.
First, make a request to get the IDs of all sources for a specific period.
https://api-metrika.yandex.net/stat/v1/data/drilldown?ids=<counter_id>&dimensions=ym:s:<attribution>TrafficSource,ym:s:<attribution>SourceEngine&metrics=ym:s:visits&date1=2025-01-01&date2=2025-01-31&attribution=lastsign
In the response, find Search engine traffic. Its id is organic.
Response with a list of traffic sources and their IDs
"data": [
{
"dimension": {
"icon_id": "1",
"icon_type": "traffic-source",
"name": "Link traffic",
"id": "referral"
},
"metrics": [
7725
],
"expand": true
},
{
"dimension": {
"icon_id": "2",
"icon_type": "traffic-source",
"name": "Search engine traffic",
"id": "organic"
},
"metrics": [
6192
],
"expand": true
},
{
"dimension": {
"icon_id": "0",
"icon_type": "traffic-source",
"name": "Direct traffic",
"id": "direct"
},
"metrics": [
3685
],
"expand": false
},
{
"dimension": {
"icon_id": "-1",
"icon_type": "traffic-source",
"name": "Internal traffic",
"id": "internal"
},
"metrics": [
705
],
"expand": false
},
{
"dimension": {
"icon_id": "7",
"icon_type": "traffic-source",
"name": "Mailing traffic",
"id": "email"
},
"metrics": [
316
],
"expand": false
},
{
"dimension": {
"icon_id": "10",
"icon_type": "traffic-source",
"name": "Messenger traffic",
"id": "messenger"
},
"metrics": [
67
],
"expand": true
},
{
"dimension": {
"icon_id": "8",
"icon_type": "traffic-source",
"name": "Social network traffic",
"id": "social"
},
"metrics": [
43
],
"expand": true
},
{
"dimension": {
"icon_id": "9",
"icon_type": "traffic-source",
"name": "Recommendation system traffic",
"id": "recommend"
},
"metrics": [
18
],
"expand": true
}
]
Now you can make the request to retrieve data on search traffic using the ID parent_id=["organic"]:
https://api-metrika.yandex.net/stat/v1/data/drilldown?ids=<counter_id>&dimensions=ym:s:<attribution>TrafficSource,ym:s:<attribution>SourceEngine&metrics=ym:s:visits&date1=2025-01-01&date2=2025-01-310&attribution=lastsign&parent_id=["organic"]