Documentation sections

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:

FieldTypeDescription
iduuidSource ID
namestringName
template_idstringCatalog template ID. A source created without a template has no such field
template_versionintegerTemplate version at the time of creation. A source without a template has no such field
cost_modelstringDefault value — cpc. The cost model is set in the campaign — see Campaign cost models
tokensarraySource tokens, always an array
postback_modestringMode of the postback to the source: single — one address for all statuses, per_status — a separate address per status
postback_urlstring or nullPostback address for the single mode
postbacksarrayRows for the per_status mode, always an array
postback_secretstring or nullIncoming postback secret: *** if set, otherwise null
capi_enabledbooleanSending events to the Facebook Conversions API
capi_pixel_idstring or nullPixel ID
capi_tokenstring or nullAccess Token: *** if set, otherwise null

Token

An element of the tokens array. The array holds up to 128 tokens.

FieldTypeRequiredDescription
namestringyesSlot: external_id, cost, sub_id_1 … sub_id_30 and others. Up to 64 bytes
paramstringyesParameter name in the link. Up to 128 bytes, must be unique within the source
aliasstringnoToken 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
placeholderstringnoParameter 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.

FieldTypeRequiredDescription
statusstringyesConversion status: lead, sale, rejected, hold or the network's own status. Up to 32 characters, saved in lowercase
urlstringyesAddress 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

http
GET /api/v1/traffic-source-templates

Returns the source template catalog. No parameters.

Response — code 200 and an object:

FieldTypeDescription
versionintegerCatalog version
itemsarrayTemplates
items[].idstringTemplate ID, for example facebook
items[].namestringName, for example Facebook Ads
items[].versionintegerTemplate version. Passed when creating a source
items[].cost_modelstringThe cost_model value for the source
items[].tokensarrayTemplate tokens, fields as in the Token section
items[].postback_urlstring or nullTemplate postback address
items[].setup_requiredbooleantrue for templates whose postback address must be filled in manually. Other templates have no such field

Sources

List sources

http
GET /api/v1/traffic-sources

Returns 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

http
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

http
POST /api/v1/traffic-sources

Creates a source from a catalog template or with the fields from the request.

FieldTypeRequiredDescription
namestringyesName
template_idstringnoTemplate ID from the catalog
template_versionintegerwith template_idTemplate version from the catalog. Must match the current one
cost_modelstringnoDefault: cpc
tokensarraynoTokens. Default: an empty array
postback_modestringnosingle or per_status. Default: single
postback_urlstring or nullnoPostback address for the single mode
postbacksarraynoRows for the per_status mode
postback_secretstring or nullnoIncoming postback secret
capi_enabledbooleannoDefault: false
capi_pixel_idstring or nullnoPixel ID
capi_tokenstring or nullnoAccess 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.

bash
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:

CodecodeWhen
400bad_requestThe body could not be parsed as JSON
400validationAn error in postback_mode, postback_url or the postbacks rows, or more than 20 rows. The text names the field or the row number
409template_changedThe catalog has no template with this template_id and template_version. Request the catalog again
422validationNo 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

http
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.

FieldTypeRequiredDescription
namestringyesName
tokensarraynoReplaces all tokens. Without the field, the tokens are deleted
postback_urlstring or nullnoWithout the field, null or an empty string — the address is cleared
capi_enabledbooleannoWithout the field — false
capi_pixel_idstring or nullnoWithout the field or null — cleared
cost_modelstringnoWithout the field or an empty string — not changed
postback_modestringnoWithout the field or an empty string — not changed
postbacksarraynoWithout the field or null — not changed. An empty array [] deletes all rows
postback_secretstring or nullnoNew secret. Without the field, null, an empty string or *** — the previous secret stays
capi_tokenstring or nullnoNew token. Without the field, null, an empty string or *** — the previous token stays
clear_postback_secretbooleannotrue deletes the incoming postback secret
clear_capi_tokenbooleannotrue 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.

Warning.

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

http
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

http
POST /api/v1/traffic-sources/{id}/apply/preview

Shows 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:

FieldTypeDescription
iduuidPreview ID for the apply method
expires_atstringThe time until which the preview can be applied: 15 minutes from the request
campaignsarrayThe source's campaigns
campaigns[].iduuidCampaign ID
campaigns[].namestringCampaign name
campaigns[].beforearrayThe campaign's current parameters: {name, param, value} objects
campaigns[].afterarrayParameters after applying
campaigns[].changedbooleantrue if the parameters will change

Errors:

CodecodeWhen
400bad_request{id} is not a UUID
404not_foundThe source does not exist
422batch_too_largeThe source has more than 2000 campaigns
422invalid_paramsThe parameters of one of the campaigns are saved in an invalid format
422validationAn error in the source's saved tokens

Apply a preview

http
POST /api/v1/traffic-sources/{id}/apply

Writes the parameters from the preview's after field into the campaigns. {id} in the path is the source ID.

FieldTypeRequiredDescription
preview_iduuidyesThe id field from the preview response

A preview can be applied only with a token of the same user who requested it.

bash
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:

json
{
  "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:

ValueWhat it means
updatedThe campaign's parameters were replaced
unchangedThe campaign had no differences from the source
conflictThe campaign's parameters changed after the preview. The campaign was not touched
unavailableThe 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:

CodecodeWhen
400bad_request{id} or preview_id is not a UUID
404not_foundThis source and user have no preview with this preview_id
409preview_expiredMore than 15 minutes have passed. Get a new preview
409source_changedThe source's tokens changed after the preview. Get a new preview
422preview_requiredThe body has no preview_id, or the body could not be parsed as JSON
Updated Need help? ↗