Admin API: traffic sources
Eight methods for working with sources: the template catalog, creating and editing, tokens, postback, secrets and applying parameters to campaigns.
The methods on this page do the same as the Sources («Источники») section in the panel: they create traffic sources, change their tokens and postback, and apply parameters to campaigns. All methods require a token with Full access («Полный доступ») (full). Authorization is described on the Admin API: overview and authorization page, and the request format and common error codes on the Request, response and error format page.
Source object
The list, read, create and update methods return a source in this form:
| Field | Type | Description |
|---|---|---|
id | uuid | Source ID |
name | string | Name |
template_id | string | Catalog template ID. A source created without a template has no such field |
template_version | integer | Template version at the time of creation. A source without a template has no such field |
cost_model | string | Default value — cpc. The cost model is set in the campaign — see Campaign cost models |
tokens | array | Source tokens, always an array |
postback_mode | string | Mode of the postback to the source: single — one address for all statuses, per_status — a separate address per status |
postback_url | string or null | Postback address for the single mode |
postbacks | array | Rows for the per_status mode, always an array |
postback_secret | string or null | Incoming postback secret: *** if set, otherwise null |
capi_enabled | boolean | Sending events to the Facebook Conversions API |
capi_pixel_id | string or null | Pixel ID |
capi_token | string or null | Access Token: *** if set, otherwise null |
Token
An element of the tokens array. The array holds up to 128 tokens.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Slot: external_id, cost, sub_id_1 … sub_id_30 and others. Up to 64 bytes |
param | string | yes | Parameter name in the link. Up to 128 bytes, must be unique within the source |
alias | string | no | Token name. Up to 160 bytes: that is 160 Latin characters or 80 Cyrillic ones. If the name is empty, the response has no such field |
placeholder | string | no | Parameter value in the link — the ad platform's macro. Up to 1024 bytes |
Leading and trailing spaces in name and param are dropped.
Postback row
An element of the postbacks array. The array holds up to 20 rows.
| Field | Type | Required | Description |
|---|---|---|---|
status | string | yes | Conversion status: lead, sale, rejected, hold or the network's own status. Up to 32 characters, saved in lowercase |
url | string | yes | Address with macros. Same requirements as for postback_url |
A postback address is a full http:// or https:// address up to 2048 characters, without spaces or line breaks. Curly braces are allowed only around macros.
In the single mode, postback_url is sent and the postbacks rows are not used. In the per_status mode, the postbacks rows with a matching status are sent and postback_url is not used.
Secrets
The values of postback_secret and capi_token cannot be read through the API: responses contain *** instead. You can change or delete a secret with the Update a source method.
Template catalog
Get the template catalog
GET /api/v1/traffic-source-templatesReturns the source template catalog. No parameters.
Response — code 200 and an object:
| Field | Type | Description |
|---|---|---|
version | integer | Catalog version |
items | array | Templates |
items[].id | string | Template ID, for example facebook |
items[].name | string | Name, for example Facebook Ads |
items[].version | integer | Template version. Passed when creating a source |
items[].cost_model | string | The cost_model value for the source |
items[].tokens | array | Template tokens, fields as in the Token section |
items[].postback_url | string or null | Template postback address |
items[].setup_required | boolean | true for templates whose postback address must be filled in manually. Other templates have no such field |
Sources
List sources
GET /api/v1/traffic-sourcesReturns all of the team's sources. No parameters.
Response — code 200 and an array of source objects, newest first. There is no pagination.
Get a source
GET /api/v1/traffic-sources/{id}Returns one source. {id} in the path is the source ID.
Response — code 200 and a source object.
Errors: 400 bad_request — {id} is not a UUID, 404 not_found — the source does not exist.
Create a source
POST /api/v1/traffic-sourcesCreates a source from a catalog template or with the fields from the request.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Name |
template_id | string | no | Template ID from the catalog |
template_version | integer | with template_id | Template version from the catalog. Must match the current one |
cost_model | string | no | Default: cpc |
tokens | array | no | Tokens. Default: an empty array |
postback_mode | string | no | single or per_status. Default: single |
postback_url | string or null | no | Postback address for the single mode |
postbacks | array | no | Rows for the per_status mode |
postback_secret | string or null | no | Incoming postback secret |
capi_enabled | boolean | no | Default: false |
capi_pixel_id | string or null | no | Pixel ID |
capi_token | string or null | no | Access Token |
If template_id is passed, the tokens, cost_model and postback_url fields are taken from the template, and the values from the request are ignored. The postback mode becomes single, and the postbacks rows are empty. For a template with setup_required, the postback address stays empty: set it with the Update a source method.
Response — code 201 and the created source object.
curl -X POST https://panel.example.com/api/v1/traffic-sources \
-H "Api-Key: <token>" \
-H "Content-Type: application/json" \
-d '{"name":"Facebook Ads","template_id":"facebook","template_version":1}'Errors:
| Code | code | When |
|---|---|---|
400 | bad_request | The body could not be parsed as JSON |
400 | validation | An error in postback_mode, postback_url or the postbacks rows, or more than 20 rows. The text names the field or the row number |
409 | template_changed | The catalog has no template with this template_id and template_version. Request the catalog again |
422 | validation | No name — the message name is required. Or an error in tokens: more than 128 tokens, empty name or param, length exceeded, repeated param |
Postback errors come with code 400, name and token errors with code 422. Postback error texts are covered on the S2S postback to the source page, token error texts on the Source tokens page.
Update a source
PUT /api/v1/traffic-sources/{id}Saves a source. {id} in the path is the source ID. The body replaces the record, so pass the whole source: get it with the Get a source method, change the fields you need and send it back. Secrets shown as *** are kept.
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Name |
tokens | array | no | Replaces all tokens. Without the field, the tokens are deleted |
postback_url | string or null | no | Without the field, null or an empty string — the address is cleared |
capi_enabled | boolean | no | Without the field — false |
capi_pixel_id | string or null | no | Without the field or null — cleared |
cost_model | string | no | Without the field or an empty string — not changed |
postback_mode | string | no | Without the field or an empty string — not changed |
postbacks | array | no | Without the field or null — not changed. An empty array [] deletes all rows |
postback_secret | string or null | no | New secret. Without the field, null, an empty string or *** — the previous secret stays |
capi_token | string or null | no | New token. Without the field, null, an empty string or *** — the previous token stays |
clear_postback_secret | boolean | no | true deletes the incoming postback secret |
clear_capi_token | boolean | no | true deletes the Access Token |
The template_id and template_version fields are not changed by this method.
Response — code 200 and a source object. The new tokens apply to clicks of all the source's campaigns right away. The parameters in campaign links do not change — that is what applying parameters is for.
A request without tokens, postback_url, capi_enabled or capi_pixel_id clears these fields. After the secret is deleted, postbacks for the source's clicks are accepted without the secret parameter.
Errors: the same 400 and 422 as on creation, 400 bad_request — {id} is not a UUID, 404 not_found — the source does not exist.
Delete a source
DELETE /api/v1/traffic-sources/{id}Deletes a source. Campaigns stay, and their source field becomes empty. {id} in the path is the source ID.
Response — code 204 with no body.
Errors: 400 bad_request — {id} is not a UUID, 404 not_found — the source does not exist.
Applying parameters to campaigns
Applying takes two requests: first a preview, then the commit. The merge rules are described on the Applying a source to campaigns page.
Get a preview of the changes
POST /api/v1/traffic-sources/{id}/apply/previewShows how the source's saved tokens will change the parameters of each campaign with this source. Nothing changes in the campaigns. No request body is needed; {id} in the path is the source ID.
Response — code 200 and an object:
| Field | Type | Description |
|---|---|---|
id | uuid | Preview ID for the apply method |
expires_at | string | The time until which the preview can be applied: 15 minutes from the request |
campaigns | array | The source's campaigns |
campaigns[].id | uuid | Campaign ID |
campaigns[].name | string | Campaign name |
campaigns[].before | array | The campaign's current parameters: {name, param, value} objects |
campaigns[].after | array | Parameters after applying |
campaigns[].changed | boolean | true if the parameters will change |
Errors:
| Code | code | When |
|---|---|---|
400 | bad_request | {id} is not a UUID |
404 | not_found | The source does not exist |
422 | batch_too_large | The source has more than 2000 campaigns |
422 | invalid_params | The parameters of one of the campaigns are saved in an invalid format |
422 | validation | An error in the source's saved tokens |
Apply a preview
POST /api/v1/traffic-sources/{id}/applyWrites the parameters from the preview's after field into the campaigns. {id} in the path is the source ID.
| Field | Type | Required | Description |
|---|---|---|---|
preview_id | uuid | yes | The id field from the preview response |
A preview can be applied only with a token of the same user who requested it.
curl -X POST https://panel.example.com/api/v1/traffic-sources/3f6c1c1e-8a52-4a4b-9c0d-2b7e5d1a9f10/apply \
-H "Api-Key: <token>" \
-H "Content-Type: application/json" \
-d '{"preview_id":"b1d7a0c4-52e3-4c8f-a6b9-0e4f7d2c3a15"}'Response — code 200 and an object:
{
"updated": 1,
"total": 2,
"outcomes": [
{"id": "7a1e0f3b-6c2d-4e58-b9a1-3d5c8e2f4a60", "state": "updated"},
{"id": "c4b2d9e1-0f7a-4b36-8d5e-1a9c6f3b2e74", "state": "conflict"}
]
}updated is the number of updated campaigns, total is the number of campaigns in the preview. state values:
| Value | What it means |
|---|---|
updated | The campaign's parameters were replaced |
unchanged | The campaign had no differences from the source |
conflict | The campaign's parameters changed after the preview. The campaign was not touched |
unavailable | The campaign was deleted or a different source is selected in it. The campaign was not touched |
For campaigns with the conflict and unavailable outcomes, get a new preview and apply it. A repeated request with the same preview_id returns the saved result and changes nothing.
Errors:
| Code | code | When |
|---|---|---|
400 | bad_request | {id} or preview_id is not a UUID |
404 | not_found | This source and user have no preview with this preview_id |
409 | preview_expired | More than 15 minutes have passed. Get a new preview |
409 | source_changed | The source's tokens changed after the preview. Get a new preview |
422 | preview_required | The body has no preview_id, or the body could not be parsed as JSON |