Create a template in the editor
action=create-banner-as-template
5 side effects
MCP: opt-in
Returns an editor link that opens the editor on a new banner, which the user saves as a template.
MCP tool:
editor_create_template, only with the login tools header.
Use with AI
Use this action when an end user makes templates for other users. Send the browser of the user to the link in the answer, in the same window or in an iframe. The link signs the user in and opens the editor. Your server makes the API call, because the call needs your secret key.
It takes the parameters of create-banner, plus template_name, category_id, category_type and tags. These four fill in the template data that the editor shows when the user saves the template.
Side effects
- The API signs in the end user with this identifier. If the identifier is new, the API first creates that user.
- This sign-in serves this one request: it ends no other session of the user, so an open editor keeps working.
- The link in the answer is a sign-in link for that user. Anyone who has it can open the editor as that user from one hour before t until one hour after t. They can reuse it in that time. Keep it private, like a password.
- When a browser opens the link, the API signs the user in to the editor. Unless your white label allows multiple logins, that sign-in ends the user's other editor sessions, and an open editor loses its unsaved work.
- No banner exists until the user saves it in the editor.
Parameters
Every request also has the
common parameters
client_id, t, signature and
action.
| Name | Description | Allowed values |
|---|---|---|
identifier
Required
user identifier |
The key of the end user in your own system, for example a user id or an email address. It has at most 255 characters. A new identifier can contain only letters, digits, spaces and @ # $ & . - _ /.
Example: user-42 | At most 255 characters |
name
Optional
text |
The display name of the end user. The API uses it only when it creates the user. If you leave it out, the display name is the identifier. A new display name can contain only letters, digits, spaces and @ # $ & . - _ /.
Example: Anna Smith | |
banner_name
Optional
text |
The name of the new banner, shown in the editor. The API adds it to the editor link without URL encoding. Names with & or # are not tested.
Example: Summer sale | |
width
Optional
whole number |
The width of the new banner in pixels, from 10 to 3000. Send width and height together. The editor then opens a blank banner of that size.
Example: 300 | 10 to 3000 |
height
Optional
whole number |
The height of the new banner in pixels, from 10 to 3000. Send width and height together. The editor then opens a blank banner of that size.
Example: 250 | 10 to 3000 |
from_banner
Optional
hash |
The hash of a single banner to copy. The editor opens a copy of it. The parameter name from, which older docs show, does not work.
Example: bduny9j1 | |
sizes
Optional
list of sizes |
A comma-separated list of sizes for the editor, for example 300x250,728x90. For a single banner, the API passes the list to the editor as it is.
Example: 300x250,728x90 | |
hide_my_uploads
Optional
true or false |
If true, the editor hides the list of the files that the user uploaded. Only the value true counts.
Example: true | true or false |
mode
Optional
one value from a list |
redirect is for an editor in its own browser window. iframe is for an editor inside an iframe on your page. In iframe mode, the editor posts BS.useBanner:, BS.useBannerSet: and BS.closeBannerEditor messages to your page instead of opening use_banner_url or cancel_url. The editor sends them with the target origin *, so make sure that a message comes from the editor origin before you use it.
Example: iframe | redirect or iframeDefault: redirect |
cancel_url
Optional
URL |
The page that the editor opens when the user closes it, in redirect mode.
Example: https://www.example.com/banners | |
use_banner_url
Optional
URL |
The page that the editor opens after the user uses the banner, in redirect mode. The editor adds banner= and the hash to its query string.
Example: https://www.example.com/banners/done | |
multiple_slides
Optional
true or false |
If true, the user can add more than one slide. If false, the banner has one slide. If you leave it out, the configuration of your white label applies.
Example: true | true or false |
animations
Optional
true or false |
If true, the editor offers animations and animated templates. If false, it hides them. If you leave it out, the configuration of your white label applies.
Example: true | true or false |
template_name
Required
text |
The name of the new template. It must not be empty.
Example: Summer sale template | |
category_id
Required
whole number |
The id of the template category. With category_type custom, it must be a custom category of your white label. Otherwise, it must be a global template category.
Example: 12 | |
category_type
Optional
one value from a list |
custom for a custom category of your white label, default for a global template category. If you leave it out, the API uses the global categories.
Example: custom | custom or default |
tags
Optional
text |
Tags for the template, at most 255 characters.
Example: summer,sale | At most 255 characters |
Response
| Field | Type | Description |
|---|---|---|
code |
integer | 200 when the call worked. Every answer comes with HTTP 200, errors too, so read this field. |
data.url |
string | The editor link on your white label domain, without the protocol. Add https:// before you use it. It keeps the query string and the signature of your request. |
Example
{
"code": 200,
"data": {
"url": "client.example.com/wapix/2.0/?action=create-banner-as-template&category_id=12&category_type=custom&client_id=2AF832&identifier=user-42&template_name=Summer%20sale%20template&t=1793361600&signature=62433e2d39449ee5ff35bfeea66ed376479a7071"
}
}
Errors
The error code is in the code field. The
errors guide explains the
answer shapes and the codes that come as text.
| Code | Meaning | What to do |
|---|---|---|
| 510 The request has expired | The time in t is more than one hour away from the clock of the API server. The API accepts a request from one hour before t until one hour after t. A missing t gives the same code. | When you sign the request, set t to the current Unix time in seconds. Make sure that the clock of your server is correct. Sign the request again if it is older than one hour. Send every parameter in the query string, because the API does not read a POST body. |
| 512 Client id not found | The API does not know this client id. | Make sure that client_id is the client id of your API credentials, with no extra spaces. |
| 513 Invalid signature | The signature does not match the parameters and your secret key. | Sign with the secret key of your white label, not with the client id. Use every query parameter except signature. Sort the names in byte order. Join each name and its value with no separator. Compute the HMAC-SHA1 of the result as 40 lowercase hex characters. Sign the values before URL encoding. |
| 515 Disabled domain | Your white label is not active. | Contact Bannersnack support. |
| 520 Missing mandatory parameter "<name>" | A required parameter is missing. The message names it. A missing or unknown action also gives this code, with the name action. | Add the parameter that the message names. If the message names network_id, Ad Network Id or Ad Network ID, send the id in ad_network. If it names Adtag type, send adtag_type. |
| 500 <the text of the failure> | The sign-in step inside the API failed. The message has the details. | Try again in a few minutes. If it keeps happening, contact Bannersnack support and send them the message. |
| 516 User disabled | The end user with this identifier is disabled. | Enable the user again, or use another identifier. |
| 517 Can't create more banners | The end user reached the banner limit of your white label. The count has the published HTML5 banners that the user made since the last billing date. | Wait for the next billing period, or ask Bannersnack support for a higher limit. |
| 521 Internal server error | category_type is not custom or default. | Make sure that every value matches this reference, then try again. If the values are right, try again in a few minutes. |
| 531 Banner not found | The banner in from_banner does not exist, or it is a banner set. | Make sure that the hash is right. Make sure that it is a banner or a banner set, as the action needs. Read the rules of the action. For a generation action, give each layer on a slide of the source its own name. |
| 535 Invalid banner size | width or height is outside 10 to 3000. | Send both width and height as whole numbers from 10 to 3000. |
| 539 Tags length must not exceed 255 | tags is longer than 255 characters. | Send at most 255 characters in tags. |
| 540 Invalid user name. <the characters that it can contain> | The display name in name has a character that is not allowed. The API makes this test only when it creates the user. | Use only letters, digits, spaces and @ # $ & . - _ / in name. |
| 541 Invalid user identifier. <the characters that it can contain> | The identifier has a character that is not allowed. The API makes this test only when it creates the user. | Use only letters, digits, spaces and @ # $ & . - _ / in identifier. |
| 547 Invalid template name | template_name is empty. | Send a template name. |
| 548 Category not found | category_id is missing, or no category with this id exists for the category type. | With category_type custom, send the id of a custom category of your white label. Otherwise, send the id of a global template category. |
Code examples
This request returns a sign-in link for this user. Anyone who has the command or the link can open the editor as this user. Do not share it.
These examples send the required parameters with example values.
Replace YOUR_CLIENT_ID with your client id. The
Node, PHP and Python examples sign the request themselves. They
read your secret key from the environment variable
BANNERSNACK_SECRET_KEY.
The cURL example shows the form of a signed request. It has an
example signature and an old t, so the API refuses
it. Use Try it to get a cURL command that is signed with your
own key.
cURL
curl -sS 'https://enterprise.bannersnack.com/wapi/2.0/?action=create-banner-as-template&category_id=12&client_id=YOUR_CLIENT_ID&identifier=user-42&t=1793361600&template_name=Summer%20sale%20template&signature=6bf06a66eb63b6fe19ab95a8a2a1319b9c92493f'
Node
import { createHmac } from 'node:crypto';
const params = {
"action": "create-banner-as-template",
"category_id": "12",
"client_id": "YOUR_CLIENT_ID",
"identifier": "user-42",
"template_name": "Summer sale template"
};
params.t = String(Math.floor(Date.now() / 1000));
const data = Object.keys(params).sort().map(key => key + params[key]).join('');
params.signature = createHmac('sha1', process.env.BANNERSNACK_SECRET_KEY).update(data).digest('hex');
const url = "https://enterprise.bannersnack.com/wapi/2.0/" + '?' + new URLSearchParams(params);
const response = await fetch(url);
console.log(await response.json());
PHP
<?php
$params = [
'action' => 'create-banner-as-template',
'category_id' => '12',
'client_id' => 'YOUR_CLIENT_ID',
'identifier' => 'user-42',
'template_name' => 'Summer sale template',
];
$params['t'] = (string) time();
ksort($params);
$data = '';
foreach ($params as $key => $value) {
$data .= $key . $value;
}
$params['signature'] = hash_hmac('sha1', $data, getenv('BANNERSNACK_SECRET_KEY'));
$url = 'https://enterprise.bannersnack.com/wapi/2.0/' . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
echo file_get_contents($url), PHP_EOL;
Python
import hashlib, hmac, os, time, urllib.parse, urllib.request
params = {
"action": "create-banner-as-template",
"category_id": "12",
"client_id": "YOUR_CLIENT_ID",
"identifier": "user-42",
"template_name": "Summer sale template"
}
params["t"] = str(int(time.time()))
data = "".join(key + params[key] for key in sorted(params))
secret = os.environ["BANNERSNACK_SECRET_KEY"].encode()
params["signature"] = hmac.new(secret, data.encode(), hashlib.sha1).hexdigest()
url = "https://enterprise.bannersnack.com/wapi/2.0/" + "?" + urllib.parse.urlencode(params, quote_via=urllib.parse.quote)
with urllib.request.urlopen(url) as response:
print(response.read().decode())