Embed the editor

Open the Bannersnack editor for your users in the same window, in a new window or in an iframe, and learn when they save.

Your users make and change banners in the Bannersnack editor. Your server asks the API for an editor link. The browser of the user opens the link, and the editor opens on your white label domain.

The editor link actions

ActionWhat it does
create-banner Returns an editor link that opens the editor on a new single banner for an end user.
edit-banner Returns an editor link that opens the editor on an existing banner of an end user.
create-banner-as-template Returns an editor link that opens the editor on a new banner, which the user saves as a template.
create-bannerset Returns an editor link that opens the generator on a new banner set for an end user.
edit-bannerset Returns an editor link that opens the generator on an existing banner set of an end user.

Open the editor

  1. On your server, call an editor action with the identifier of the user, for example create-banner.
  2. Read data.url in the answer. It has no protocol, so add https:// in front of it.
  3. Send the browser of the user to the link: in the same window, in a new window or in an iframe.
  4. The link signs the user in and opens the editor.
{
  "code": 200,
  "data": {
    "url": "client.example.com/wapix/2.0/?action=create-banner&client_id=2AF832&identifier=user-42&mode=iframe&t=1793361600&signature=62433e2d39449ee5ff35bfeea66ed376479a7071"
  }
}

The editor link is a sign-in link

Anyone who has the link can open the editor as that user, from one hour before t until one hour after t, any number of times. Make the link when the user opens the editor, and send it only to that user. Do not store the link, write it to a log or send it by email.

The API signs the user in twice: once for the API call, which ends no other session, and once when the browser opens the link. Unless your white label allows multiple logins, the second sign-in ends the other editor sessions of that user.

Redirect mode

Redirect mode is the default. The editor fills the whole browser window. When the user uses the banner, the editor opens use_banner_url. It adds the hash in the parameter banner:

use_banner_url:  https://www.example.com/banners/done
editor opens:    https://www.example.com/banners/done?banner=bduny9j1

If use_banner_url already has a query, the editor adds &banner= instead. When the user closes the editor, it opens cancel_url. Older docs also name close_url. The API reads only cancel_url.

On the page of use_banner_url, read the banner parameter. Then call get-banner-urls for that hash to get the export links.

Iframe mode

Send mode=iframe in the editor action, and load the link in an iframe on your page. The editor then posts messages to your page instead of opening use_banner_url and cancel_url.

MessageSent whenExample
BS.useBanner: The user uses or saves a single banner. The banner hash follows the colon.BS.useBanner:bduny9j1
BS.useBannerSet: The user saves a banner set in the generator. The banner set hash follows the colon.BS.useBannerSet:bq2set7xa
BS.closeBannerEditor The user clicks the close button of the editor.BS.closeBannerEditor

The editor posts the messages with the target origin *, so any page that embeds the editor gets them. Before you use a message, make sure that it comes from your iframe and from the editor origin.

The editor origin is the scheme and the host of the editor after the link redirects. To find it, open an editor link in a browser tab and read the address. In this example, editorLink is the data.url of the answer. saveBanner and saveBannerSet are your own functions.

<iframe id="editor" title="Banner editor" width="100%" height="800"></iframe>

<script>
const EDITOR_ORIGIN = 'https://app.example.com';
const frame = document.getElementById('editor');
frame.src = 'https://' + editorLink;

window.addEventListener('message', event => {
    if (event.source !== frame.contentWindow || event.origin !== EDITOR_ORIGIN) {
        return;
    }
    if (typeof event.data !== 'string') {
        return;
    }
    if (event.data.startsWith('BS.useBanner:')) {
        const bannerHash = event.data.slice('BS.useBanner:'.length);
        saveBanner(bannerHash);
    } else if (event.data.startsWith('BS.useBannerSet:')) {
        const bannersetHash = event.data.slice('BS.useBannerSet:'.length);
        saveBannerSet(bannersetHash);
    } else if (event.data === 'BS.closeBannerEditor') {
        frame.remove();
    }
});
</script>

Iframes on a custom domain

The editor needs its session cookie. If your white label domain is under bannersnack.com, the cookie has SameSite=None and Secure, so the editor works in an iframe. On another domain, the cookie does not have these attributes. A browser that blocks third-party cookies can then block the editor in an iframe. This was not tested in every browser. If the editor does not load in an iframe, use redirect mode or a new window.

A new window

To keep your page open, open the link in a new window with window.open. Keep the window handle that it returns, and use it to focus or close the editor window. Use redirect mode in a new window, because the editor posts its messages only to a parent page.

Session settings

When the browser opens the link, the API stores these parameters for the editor session of the user. They override the configuration of your white label for that session only.

ParameterEffect
mode 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.
cancel_url The page that the editor opens when the user closes it, in redirect mode.
use_banner_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.
multiple_slides 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.
animations 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.
hide_my_uploads If true, the editor hides the list of the files that the user uploaded. Only the value true counts.

create-banner also takes width, height and sizes. create-banner-as-template also takes template_name, category_id, category_type and tags, which fill in the template data in the editor. Older docs describe the values of multiple_slides and animations the other way round.

Errors of the editor actions

Before it makes the link, the API checks the user and the sizes. These errors apply only to the editor actions:

CodeMeaning
516 The end user with this identifier is disabled.
517 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.
535 width or height is outside 10 to 3000.
536 sizes is not a comma-separated list of WIDTHxHEIGHT items, or a number in it is below 10.
537 One or more sizes are not in the size list of your white label. The message lists them.