Exports

Start an export, wait until the file is ready, and download it.

start-banner-export makes a file from a banner, for example an MP4 video or a PDF. The export runs in the background. get-banner-urls tells you when the file is ready, and it gives you the link to the file.

You do not start the JPG, PNG and HTML5 exports. get-banner-urls lists them with the other types. If the HTML5 zip does not exist yet, each call to get-banner-urls queues a build of it.

Export types

TypeNamePermissionEntry in get-banner-urlsNeeds an ad networkOther spellings
mp4 MP4 videoMP4 and GIF exportmp4NoMP4
animated-gif Animated GIFMP4 and GIF exportanimated-gifNoanimated_gif and ANIMATED_GIF
optimized-animated-gif Optimized animated GIFMP4 and GIF exportoptimized-animated-gifNoanimated_gif_low and ANIMATED_GIF_LOW
pdf PDFPDF exportpdfNoPDF
pdf-print Print PDFPDF exportpdf-printNopdf_print and PDF_PRINT
amp AMPNo permission neededampNoAMP
ad-tag-html5 HTML5 ad tagAd tag embed downloadNone. See Ad networks.Yesad_tag_html5 and AD_TAG_HTML5
ad-tag-mraid MRAID ad tagAd tag embed downloadNone. See Ad networks.Yesad_tag_mraid and AD_TAG_MRAID

Each type needs a permission of your white label, except AMP. Without the permission, the API answers 514. Ask Bannersnack support to turn on a permission. The API also accepts the other spellings of a type, in any letter case.

Start an export and wait for it

  1. Call start-banner-export with banner_hash and type. For an ad tag type, also send ad_network.
  2. Read the answer. {"code":200,"data":{"status":"Done"}} means that the API queued the export. The file is not ready yet.
  3. Wait 2 seconds, then call get-banner-urls with the same banner_hash.
  4. Find the entry whose type is the export type. When its status is done, download the file from its url.
  5. If the status is not done, wait and call again. Double the wait each time, up to 10 seconds.
  6. Stop after 5 minutes. Then start the export again, or contact Bannersnack support.

In this example, callApi is your function that signs a request and sends it, as in Getting started.

const delays = [2000, 4000, 8000];

async function waitForExport(bannerHash, type) {
    const started = Date.now();
    for (let attempt = 0; Date.now() - started < 5 * 60 * 1000; attempt++) {
        await new Promise(resolve => setTimeout(resolve, delays[attempt] ?? 10000));
        const answer = await callApi('get-banner-urls', { banner_hash: bannerHash });
        if (answer.code !== 200) {
            throw new Error('get-banner-urls failed: ' + JSON.stringify(answer));
        }
        const entry = answer.data.find(item => item.type === type);
        if (entry && entry.status === 'done') {
            return entry.url;
        }
    }
    throw new Error('The export is not ready after 5 minutes');
}

await callApi('start-banner-export', { banner_hash: 'bduny9j1', type: 'mp4' });
const url = await waitForExport('bduny9j1', 'mp4');

Status values

StatusMeaning
none No file yet. After you start an export, the status can stay none until the file is ready. So none does not tell you that the export failed or did not start.
pending The export runs, or the file does not exist yet.
done The file is ready. Download it from url.

jpg and png show pending until they exist. html5 shows done when its zip is ready, and pending before that. While the HTML5 zip is not ready, its url has no address before ?t=.

Each poll signs in the owner of the banner

Each call to get-banner-urls signs in the owner of the banner for that one request. The call ends no other session, so an open editor keeps working. While the HTML5 zip does not exist, each call also queues a build of it.

  • Poll only after you start an export.
  • Wait between calls, as the steps above show.
  • Stop when the export is ready, or after 5 minutes.
  • Do not poll while the owner edits the banner.

After a change to the banner

When the banner is saved again, the API resets its exports, AMP included. Start the exports again after each change.

Banner sets

start-banner-export takes one single banner, not a banner set. To export a banner set, start the export for each banner in it. get-bannerset-urls lists the banners of a set, each with its nine export entries. get-user-banners with bannerset_hash also lists them.

Drafts and deleted banners

start-banner-export also exports a draft or a deleted banner. get-banner-urls reads only published, active banners, so you cannot read back such an export.