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
| Type | Name | Permission | Entry in get-banner-urls | Needs an ad network | Other spellings |
|---|---|---|---|---|---|
mp4 |
MP4 video | MP4 and GIF export | mp4 | No | MP4 |
animated-gif |
Animated GIF | MP4 and GIF export | animated-gif | No | animated_gif and ANIMATED_GIF |
optimized-animated-gif |
Optimized animated GIF | MP4 and GIF export | optimized-animated-gif | No | animated_gif_low and ANIMATED_GIF_LOW |
pdf |
PDF export | pdf | No | PDF |
|
pdf-print |
Print PDF | PDF export | pdf-print | No | pdf_print and PDF_PRINT |
amp |
AMP | No permission needed | amp | No | AMP |
ad-tag-html5 |
HTML5 ad tag | Ad tag embed download | None. See Ad networks. | Yes | ad_tag_html5 and AD_TAG_HTML5 |
ad-tag-mraid |
MRAID ad tag | Ad tag embed download | None. See Ad networks. | Yes | ad_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
-
Call
start-banner-exportwithbanner_hashand type. For an ad tag type, also sendad_network. -
Read the answer.
{"code":200,"data":{"status":"Done"}}means that the API queued the export. The file is not ready yet. -
Wait 2 seconds, then call
get-banner-urlswith the samebanner_hash. -
Find the entry whose
typeis the export type. When itsstatusisdone, download the file from itsurl. -
If the status is not
done, wait and call again. Double the wait each time, up to 10 seconds. - 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
| Status | Meaning |
|---|---|
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.