POST /v1/reports/path_to_conversion?project_id={project_id} {
"ResponseType": "JSON",
"Fields": ["InteractionTime", "InteractionType", "InteractionUrlPath"],
"InteractionFilter": {
"DateFrom": "2024-01-01",
"DateTo": "2024-01-31",
"InteractionType": ["PageView", "Click"]
},
"Offset": 0,
"Limit": 1000
}
curl -X POST "https://api.targetads.io/v1/reports/raw_reports?project_id=12486" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ResponseType": "JSON",
"Fields": [
"InteractionTime",
"InteractionType",
"InteractionUrlPath",
"InteractionDeviceID"
],
"InteractionFilter": {
"DateFrom": "2024-01-01",
"DateTo": "2024-01-31",
"InteractionType": ["PageView"]
},
"Limit": 1000
}' curl -X POST "https://api.targetads.io/v1/reports/raw_reports?project_id=12486" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ResponseType": "JSON",
"Fields": [
"InteractionTime",
"InteractionType",
"InteractionMediaCampaignName",
"InteractionUtmSource",
"InteractionUtmMedium",
"InteractionUtmCampaign"
],
"InteractionFilter": {
"DateFrom": "2024-01-01",
"DateTo": "2024-01-31",
"InteractionType": ["Click"],
"MediaCampaignId": [12345, 12346]
}
}' curl -X POST "https://api.targetads.io/v1/reports/raw_reports?project_id=12486" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ResponseType": "JSON",
"Fields": [
"InteractionTime",
"InteractionDeviceID",
"InteractionEcomId",
"InteractionEcomAmount",
"InteractionEcomItemsName",
"InteractionEcomItemsPrice"
],
"InteractionFilter": {
"DateFrom": "2024-01-01",
"DateTo": "2024-01-31",
"InteractionType": ["Purchase"]
}
}' # Первая страница
curl -X POST "https://api.targetads.io/v1/reports/raw_reports?project_id=12486" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"ResponseType": "JSON",
"Fields": ["InteractionTime", "InteractionType", "InteractionDeviceID"],
"InteractionFilter": {
"DateFrom": "2024-01-01",
"DateTo": "2024-01-31",
"InteractionType": ["PageView"]
},
"Offset": 0,
"Limit": 10000
}'
# Вторая страница
# ... изменить Offset на 10000 {
"data": [
{
"InteractionTime": "2024-01-15 10:30:45",
"InteractionType": "PageView",
"InteractionUrlPath": "/products/item-123",
"InteractionDeviceID": "abc123def456"
},
{
"InteractionTime": "2024-01-15 10:31:20",
"InteractionType": "Click",
"InteractionUrlPath": "/checkout",
"InteractionDeviceID": "abc123def456"
}
],
"count": 2,
"has_more": false
} {
"ErrorCode": 400,
"ErrorMessage": "validate error",
"Errors": [
{
"Error": true,
"FailedField": "Fields",
"Tag": "required",
"Value": null
}
]
} Лимиты и ограничения
API имеет технические ограничения, которые следует
учитывать при построении интеграции:
Таймаут: 300 секунд
# Получить список кампаний
campaigns = get_campaigns(project_id)
# Запросить данные по каждой кампании
for campaign in campaigns[:10]: # По 10 кампаний за раз
data = get_raw_data(
project_id=project_id,
campaign_ids=[campaign['placement_id']]
) offset = 0
limit = 100000
all_data = []
while True:
response = get_raw_data(offset=offset, limit=limit)
all_data.extend(response['data'])
if not response['has_more']:
break
offset += limit from datetime import datetime, timedelta
def split_by_weeks(date_from, date_to):
current = datetime.strptime(date_from, '%Y-%m-%d')
end = datetime.strptime(date_to, '%Y-%m-%d')
while current < end:
week_end = min(current + timedelta(days=7), end)
yield current.strftime('%Y-%m-%d'), week_end.strftime('%Y-%m-%d')
current = week_end import requests
import time
def get_raw_data_with_retry(payload, max_retries=3):
for attempt in range(max_retries):
try:
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 429:
# Rate limit - ждем 60 секунд
time.sleep(60)
continue
if response.status_code == 500:
# Server error - retry с exponential backoff
time.sleep(2 ** attempt)
continue
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
if attempt == max_retries - 1:
raise
time.sleep(2 ** attempt)
raise Exception("Max retries exceeded")