Getting started
Your credentials, the request signature, the one-hour window and the shape of every answer.
What you need
You need two values from Bannersnack. Both come with your white label (your own branded copy of Bannersnack).
- The client id. It tells the API which white label sends the request.
- The secret key. It signs your requests. It has 32 characters.
If you do not have these values, ask Bannersnack support.
Keep the secret key on your server. Do not put it in a web page, a mobile app or a URL. Anyone who has the key can call the API as your white label.
The API sends no CORS headers, so a web page on another site cannot read its answers. Make every call from your server.
The API address
Send each request to the API on your white label domain:
https://<your white label domain>/wapi/2.0/
The API also answers at https://enterprise.bannersnack.com/wapi/2.0/. The examples on
this site use that address. Editor links always use your white label
domain.
Use version 2.0, as in the address above. In version 1, the editor actions answer with a redirect instead of JSON.
Send a request
Send every request as an HTTP GET. Put every parameter in the query
string, also the signature. The API reads only the query string. It
ignores a POST body, so a POST with form fields fails with 510,
because the API does not get t.
Every request has these parameters:
| Parameter | Description | Example |
|---|---|---|
client_id |
Your client id. It tells the API which white label sends the request. | 2AF832 |
t |
The current Unix time in seconds. The API accepts the request from one hour before t until one hour after t. | 1793361600 |
signature |
The HMAC-SHA1 of all other parameters with your secret key, as 40 lowercase hex characters. | 7caea37e76f4feb05a3672a7b6b4b9e49beacd28 |
action |
The name of the action, for example get-banner-urls. | get-banner-urls |
The other parameters depend on the action. The
API reference lists them for each action. Do not
use a parameter named page. The API uses this name for
itself and leaves it out of the signature.
Sign a request
-
Take every parameter of the request except
signature. Settto the current Unix time in seconds. -
Sort the parameters by name in byte order. This is the order of
ksortin PHP and of the default sort in JavaScript. Uppercase letters come before lowercase letters, and_comes before lowercase letters. - Write each name followed by its value, with no separator. Join all pairs with no separator. Use the values before URL encoding.
- Compute the HMAC-SHA1 of this text with your secret key. Write the result as 40 lowercase hex characters. An uppercase signature fails with 513.
-
Add the result as the
signatureparameter. URL-encode each value in the query string.
Use this example to test your own signer. The example secret key is not a real key.
- Parameters
-
action=get-banner-urlsbanner_hash=bduny9j1client_id=2AF832t=1793361600 - Text to sign
actionget-banner-urlsbanner_hashbduny9j1client_id2AF832t1793361600-
HMAC-SHA1 with the example secret key
example-secret-not-real 7caea37e76f4feb05a3672a7b6b4b9e49beacd28- Request URL
-
https://enterprise.bannersnack.com/wapi/2.0/?action=get-banner-urls&banner_hash=bduny9j1&client_id=2AF832&t=1793361600&signature=7caea37e76f4feb05a3672a7b6b4b9e49beacd28
These scripts sign a get-banner-urls request and send
it. They read the secret key from the environment variable
BANNERSNACK_SECRET_KEY. Replace YOUR_CLIENT_ID
with your client id.
Node
import { createHmac } from 'node:crypto';
const params = {
"action": "get-banner-urls",
"banner_hash": "bduny9j1",
"client_id": "YOUR_CLIENT_ID"
};
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' => 'get-banner-urls',
'banner_hash' => 'bduny9j1',
'client_id' => 'YOUR_CLIENT_ID',
];
$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": "get-banner-urls",
"banner_hash": "bduny9j1",
"client_id": "YOUR_CLIENT_ID"
}
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())
The time window
The API accepts a request from one hour before t until
one hour after t. Outside this window, it answers 510.
Make sure that the clock of your server is correct, for example with
NTP.
A signed request has no nonce (a value that works only once). Anyone who has a signed URL can send it again, any number of times, until the window ends. Keep signed URLs private. This is most important for editor links, because they sign in a user.
Read the answer
The API answers with HTTP 200 and JSON, also for an error. Read the
code field. The value 200 means success.
| Answer | Shape | Notes |
|---|---|---|
| Success | {"code":200,"data":...} | The result is in data. |
| Most errors | {"code":513,"data":"Invalid signature"} | The text of the error is in data. |
Errors of the read actions, for example get-banner-urls |
{"code":531,"message":"Banner not found"} | The text is in message, not in data. |
| Most errors of the generation actions | {"type":"error","code":"Banner not found","data":"531"} | The code and the text are swapped. The number is in data. |
| Errors with a text code | {"code":"INTERNAL_SERVER_ERROR","data":"Please fill in your identifier"} | code is a word in capital letters, not a number. |
An answer that is not JSON, for example an HTML page with HTTP 500 or 504, comes from a failure on the server side. The errors guide explains every code.
What every call changes
Every action except get-banner and
get-users signs in an end user before it does its
work. This is the user with the identifier of the
request, or the owner of the banner in the request.
If the identifier is new, the API first creates that user. This
also happens for an action that only reads, such as
get-user-banners.
This sign-in serves the one request and ends no other session of the user, so an open editor keeps working. Only an editor link that a browser opens signs the user in to the editor: unless your white label allows multiple logins, that ends the user's other editor sessions.
Test your credentials
- Open the home page of this site.
- Enter your client id and your secret key.
- Select Test connection.
The test sends start-banner-export without
banner_hash. The API checks t, the client id,
your white label and the signature first. Then it answers 520 for
the missing banner_hash, before it signs in a user. So
the test changes nothing.
This site sends your secret key to its own server, which signs the request and sends it to the API. The server does not store the key and does not write it to a log.
List your users
get-users lists the end users of your white label, page
by page. It needs no identifier and signs in nobody. On
its page, Try it shows the users in a table, and Use as test user
puts an identifier into the other forms of this site.
Next steps
- Exports: make MP4, GIF, PDF and AMP files.
- Embed the editor: let your users make and change banners.
- Dynamic generation: make banners from data.
- Use with AI: connect an AI tool to the API.