Admin API: streams
Admin API methods for campaign streams: list, create, edit, order, copy, templates and import, routing preview, click cap counters and statistics.
14 methods for working with campaign streams. All of them require a token with Full access («Полный доступ») (full). Authorization is described on the Admin API: overview and authorization page, and the general request and error format on the Request, response and error format page.
Stream object
This object is returned and accepted by the create and edit methods, and returned by the list and copy methods.
| Field | Type | Description |
|---|---|---|
id | string, UUID | Stream ID. Assigned by the tracker |
campaign_id | string, UUID | The stream's campaign. Taken from the request address |
name | string | Stream name |
type | string | Type: regular — Regular («Обычный»), forced — Intercepting («Перехватывающий»), default — Final («Замыкающий») |
action_type | string | Stream action, see below |
action_payload | object | Action parameters |
weight | integer | Weight in the rotation of regular streams |
position | integer | Position in the list; a lower value is higher up |
state | string | active — the stream is working, paused — on pause |
mode | string | and or or — the logic of the conditions when no groups are set |
filters | array | Selection conditions, see below |
schedule | object or null | Schedule: days — days from 1 (Monday) to 7 (Sunday), from and to — time in HH:MM, tz — time zone, for example Europe/Warsaw |
offers | array or null | Stream offers: the offer id and the share |
landers | array or null | Stream landing pages: the landing page id and the share |
click_limits | object or null | Click caps: hourly, daily, total — integers from 0 to 1,000,000,000,000, 0 — no cap; timezone — time zone, UTC by default |
For a stream without offers or landing pages, the offers and landers fields are null. If the share is not passed, it equals 100; an explicit 0 excludes the item from rotation. More about shares on the Rotation and split tests page, and about schedules and caps on the Stream schedule and click caps page.
Action and its parameters
action_type | Action in the panel | action_payload keys |
|---|---|---|
offers | Offer («Оффер») | — |
landing | Landing page («Лендинг») | — |
funnel | Landing → offer funnel («Воронка ленд→оффер») | offer_selection: before or after |
redirect | Direct URL («Прямой URL») | url — the address, required and cannot be empty; redirect_type: redirect, meta, js, direct or double_meta |
html | HTML | html — the page code |
text | Show text («Показать текст») | text — the text |
campaign | Send to campaign («Передать в кампанию») | campaign — the campaign alias |
404 | 404 stub («Заглушка 404») | — |
nothing | Nothing (empty response) («Ничего (пустой ответ)») | status — the code of the empty response, the number 200 or 204; optional, without it the response is 204 |
action_payload can also contain a target_rotation object — the selection mode, the memory period and the order of items, see Setup through the API and in a JSON file. The tracker applies it in the offers, landing and funnel actions, and validates it with any action. The panel writes this object to a stream with any action.
What each action and redirect method does is described on the Stream actions and redirect methods page.
Filters
Each element of the filters array is one condition:
| Field | Type | Description |
|---|---|---|
type | string | Condition field: geo, country, region, city, device, os, os_version, browser, browser_version, isp, connection, lang, user_agent, referer, empty_referer, bot, proxy, ip, ad_campaign_id, creative_id, keyword, sub_id_1 … sub_id_30 |
op | string | Operator: in, not_in, eq, ne, regex, not_regex. For ip, the regex and not_regex operators are not accepted. not_regex patterns are checked when the stream is saved |
values | array of strings | Values to compare with |
group | integer | Group number, from 1 |
Conditions with the same group number are combined with OR, and groups with each other with AND. If no condition has group set, the conditions are combined according to the mode field. The value format of each field is described on the Stream filters page.
Campaign streams
List streams
GET /api/v1/campaigns/{id}/streams
Returns an array of the campaign's streams in ascending order of position. {id} is the campaign ID. Error: 404 — the campaign was not found.
Create a stream
POST /api/v1/campaigns/{id}/streams
Creates a stream in the {id} campaign. The body is a stream object.
| Field | Required | Default |
|---|---|---|
action_type | yes | — |
name | no | empty string |
type | no | regular |
state | no | active |
mode | no | and |
weight, position | no | 0 |
action_payload, filters, schedule, offers, landers, click_limits | no | not set |
curl -X POST https://panel.example.com/api/v1/campaigns/3f2a1c9e-5b7d-4e8a-9c1f-0a2b3c4d5e6f/streams \
-H "Api-Key: <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "US mobile",
"type": "regular",
"action_type": "offers",
"weight": 100,
"position": 1,
"filters": [
{"type": "geo", "op": "in", "values": ["US"], "group": 1},
{"type": "device", "op": "in", "values": ["mobile"], "group": 2}
],
"offers": [{"id": "8c1d2e3f-4a5b-4c6d-8e7f-9a0b1c2d3e4f", "share": 100}],
"click_limits": {"daily": 5000, "timezone": "Europe/Warsaw"}
}'Response — code 201 and the stream object with the new id. It contains the values you passed: the default values are visible in the stream list.
Pass weight explicitly. With rotation by weight, a regular stream with weight 0 gets traffic only when all matching regular streams have weight 0. The panel sets weight 100 by default.
Errors:
400bad_request— the body could not be parsed as a JSON object;404not_found— the campaign was not found;422validation—action_type is required;Укажите адрес для действия «Прямой URL»(specify the address for the Direct URL action);неизвестный тип или оператор фильтра: <type>(unknown filter type or operator);некорректное регулярное выражение в фильтре: <type>(invalid regular expression in the filter);код ответа действия «ничего»: 200 или 204(the response code of the Nothing action: 200 or 204);Лимиты кликов: целые числа от 0 до 1 000 000 000 000(click caps: integers from 0 to 1,000,000,000,000);Неизвестный часовой пояс лимита(unknown cap time zone);оффер недоступен: <id>(offer unavailable);лендинг недоступен: <id>(landing page unavailable).
Edit a stream
PUT /api/v1/streams/{id}
Changes the {id} stream. Pass only the fields you want to change: the rest are kept. A passed field is replaced entirely. To change one key in action_payload or one offer in offers, get the stream from the list, change the object and send it in full. For a stream with the redirect action, the new action_payload must contain a non-empty url, otherwise the request returns 422 with the text Укажите адрес для действия «Прямой URL». null in schedule or click_limits removes the schedule or the caps.
curl -X PUT https://panel.example.com/api/v1/streams/b7e6d5c4-3a2f-4b1e-9d0c-8f7e6d5c4b3a \
-H "Api-Key: <token>" \
-H "Content-Type: application/json" \
-d '{"state": "paused"}'Response — code 200 and the stream object with all fields. The 400 and 422 errors are the same as when creating, except action_type is required; 404 — the stream was not found. You cannot move a stream to another campaign with this method.
Delete a stream
DELETE /api/v1/streams/{id}
Deletes the stream. Response — code 204 with no body. Error: 404 — the stream was not found.
A deleted stream does not go to the trash and cannot be restored. To take traffic off a stream temporarily, pause it with the edit method.
Set the order of streams
POST /api/v1/campaigns/{id}/streams/reorder
Arranges the campaign's streams according to the list.
| Field | Type | Required | Description |
|---|---|---|---|
ids | array of UUIDs | yes | Stream IDs in the order you need |
The first stream in the list gets position 0, the second one 1, and so on. Streams that are not in the list keep their previous position. IDs of streams from other campaigns are skipped. Response — code 204 with no body. Errors: 400 — the body could not be parsed or the list contains a value that is not a UUID; 404 — the campaign was not found.
Copy a stream
POST /api/v1/streams/{id}/clone
Creates a copy of the stream in the same campaign. No body is needed. The copy gets the name with the “ · copy” (« · копия») suffix, the paused state and a position after the last stream; offers, landing pages, filters, schedule and caps are carried over. Response — code 201 and the new stream object. Errors: 404 — the stream was not found; 422 — a condition, offer or landing page of the original stream did not pass validation.
Templates and import
How templates and files look in the panel is described on the Stream templates, export and import page.
Export a stream to a file
GET /api/v1/streams/{id}/export
Returns a portable description of the stream. Response — code 200, a Content-Disposition header with the file name stream-<id>.json, and the body:
{
"format": "tracker-stream",
"version": 1,
"stream": {"id": "", "campaign_id": "", "name": "US mobile", "type": "regular", "action_type": "offers", "state": "paused", "position": 0}
}stream contains all fields of the stream object; the example shows some of them. The stream and campaign IDs are empty, the state is paused, the position is 0. Only the keys from the actions table remain in action_payload. Error: 404 — the stream was not found.
Check a file before import
POST /api/v1/campaigns/{id}/stream-import/preview
Checks a template file for the {id} campaign and returns a ready draft. The stream is not created.
| Field | Type | Required | Description |
|---|---|---|---|
format | string | yes | tracker-stream |
version | integer | yes | 1 |
stream | object | yes | Stream object: name from 1 to 160 characters, type and action_type from the tables above |
Response — code 200 and a stream object in the paused state with a position after the campaign's last stream. To create the stream, send this object with the “Create a stream” method.
Errors: 400 — Не удалось прочитать файл шаблона (could not read the template file); 404 — the campaign was not found; 422 — the file did not pass validation, and message contains the reason, for example Нужен шаблон tracker-stream версии 1 (a tracker-stream template of version 1 is required) or Шаблон больше 256 КиБ (the template is larger than 256 KiB). All the file limits are in the File limits section.
Save a stream as a template
POST /api/v1/streams/{id}/templates
Saves the settings of the {id} stream to the personal template library of the user who created the token.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Template name, from 1 to 120 characters |
Response — code 201 and the template object: id, name, definition — the same description that the export to a file returns, created_at. Errors: 400 — Некорректный запрос (invalid request); 404 — the stream was not found; 422 — Название шаблона: от 1 до 120 символов (template name: from 1 to 120 characters) or the stream did not pass the template validation.
List templates
GET /api/v1/stream-templates
Returns an array of the token creator's templates, newest first. Element fields: id, name, definition, created_at. Templates of other users are not included in the list.
Delete a template
DELETE /api/v1/stream-templates/{id}
Deletes a template from the token creator's library. Response — code 204 with no body. Error: 404 — the template was not found. Streams created from the template do not change.
Routing preview
POST /api/v1/campaigns/{id}/routing-preview
Shows which stream of the campaign a visitor with the given parameters will get. No click is recorded, and the cap counters do not change. All fields are optional; the letter case of field names is ignored.
| Field | Type | Description |
|---|---|---|
IP | string | Visitor's IP address |
Country | string | Country code, for example US |
Region, City | string | Region and city |
Device, OS, Browser | string | Device, OS and browser, for example mobile, Android, Chrome |
Lang | string | Browser language |
ISP, Connection | string | Provider and connection type |
Referrer, UserAgent | string | Referrer and User-Agent |
Bot | boolean | Treat the visitor as a bot |
Whitepage | boolean | Calculation for filtered traffic: only final streams take part |
At | string, RFC 3339 | The moment of the calculation for the schedule and caps. The default is the current time |
SubIDs | object | sub_id values: keys sub_id_1 … sub_id_30 |
Tokens | object | Click parameter values: keys ad_campaign_id, creative_id, keyword |
curl -X POST https://panel.example.com/api/v1/campaigns/3f2a1c9e-5b7d-4e8a-9c1f-0a2b3c4d5e6f/routing-preview \
-H "Api-Key: <token>" \
-H "Content-Type: application/json" \
-d '{"Country": "US", "Device": "mobile", "OS": "Android", "Browser": "Chrome", "SubIDs": {"sub_id_1": "fb"}}'Response — code 200:
streams— the campaign's streams. Each one hasid,name,type,weight,position;eligible— whether the stream matches the visitor;filters— the result of each condition in the order of the stream'sfiltersarray;selected—truefor the selected stream;reason— an explanation as text.campaign_stateandrotation— the state and rotation mode of the campaign.at— the moment the calculation was made for.
The reason values and how to read the result are described on the Stream selection check page. Errors: 400 — the body could not be parsed; 404 — the campaign was not found; 422 — invalid IP.
Counters and statistics
Stream click cap counters
GET /api/v1/streams/{id}/click-limits
Returns how many entries are counted toward the stream's caps: hourly — for the current hour, daily — for the current day, total — in total. The hour and day are counted in the time zone of the stream's caps; if no caps are set — in UTC. Errors: 404 — the stream was not found; 503 with code unavailable — Счётчики временно недоступны (the counters are temporarily unavailable), repeat the request later.
Clicks by campaign stream
GET /api/v1/campaigns/{id}/stream-stats
Returns the clicks and unique clicks by the campaign's streams for the period.
| Parameter | Type | Description |
|---|---|---|
from | string, RFC 3339 | Start of the period. The default is 24 hours ago |
to | string, RFC 3339 | End of the period. The default is the current time |
Response — code 200 and an object with an items array. An element has three fields: stream_id, clicks, uniques. Streams without clicks for the period are not in the array. A value that is not in RFC 3339 format is replaced with the default value. Errors: 404 — the campaign was not found; 400 with code report_error — the statistics query failed.
Build other metrics by stream with the reports method grouped by stream — see Admin API: reports.
Errors
| Code | code | When |
|---|---|---|
400 | bad_request | The body is not a JSON object, or an ID in the address or in the body is not a UUID |
404 | not_found | The campaign, stream or template was not found in your team |
422 | validation | A value did not pass validation; the reason is in message |
503 | unavailable | The stream cap counters are temporarily unavailable |
Offer unavailable («оффер недоступен») or landing page unavailable («лендинг недоступен»)
There is no offer or landing page with this id in the team. Only new items are checked: the ones that were already in the stream are not rechecked when it is edited.
Changes do not show up in traffic
Changes made through the API take effect immediately. Make sure the stream is in the active state: a copy and a stream from an import are created in the paused state.