Create images from catalog
In this tutorial we are going to use the API to generate a list of images from a catalog, using nodejs
Last updated
In this tutorial we are going to use the API to generate a list of images from a catalog, using nodejs
Last updated
The objetive of this tutorial will be to generate nice images that can used as ads in any platform from a list of movies in csv format. In our file we have one line per movie with information like this:
Title
Genre
Director
Actors
Year
Rating
metascore
Description
Split
Horror,Thriller
M. Night..
James McAvoy...
2016
7.3
62
Three girls...
And we will create images like this one:
In order to use the API we need to select a template or create a new one, for this demo we are going to use the template named review that is available to all users. To select another template enter in the editor and go to the library, there you can see a list of pre made templates.
The template id can be found in the sidebar when a template is opened
For this tutorial we are going to use nodejs with the libraries axios to make http requests and csv-parse to parse our source of data.
Our first step will be to set up axios to use our API token, as well as having some parameters that we will use later in our script.
templateId we are going to use the template named review, it is a public template that can be used by anyone. It can be changed to any public template or you can create a new one from scratch.
token: Your API token that can be found under your account details.
pollingDelay: Delay between requests to check for banner changes.
bannersCount: Amount of banners to create.
modes: Modes to create the banners. Valid modes are html5, png, jpeg, webp and video. More information can be found in the API documentation
axios.defaults.headers.common: We add authentication to all axios requests.
For banner creation were are going to create a function that with a templateId, modes and movie parameter will request a template creation.
The API parameters that we are going to use are:
sizeIds: 'all': The template that we are using includes 3 different sizes (980x300, 320x320 and 160x600) to use all of them we set this parameter to 'all'. If we remove this parameter only the default size will be used.
overrides: With this parameter we override the default template content. We use the name of the item we want to override, valid properties are text, url (for external images) and css.
templateId: Id of the template we want to use, previously set on configuration block.
modes: Modes for the resulting banners, previously set on configuration block.
Complete information of all the parameters can be found here. The response of this request will be a banner object.
Banner creation is a async operation, for that reason we need to do a polling to check when a banner is ready. With the following function we will make requests until the banner is ready.
Then to wait for a list of banners to be ready we use the follow function:
Now that we all the different parts we just need to call our creation function together with our check for banner ready:
This will print in the console something like:
In url you can find our resulting banner.
Full source code example can be found here: