Export ZIP
Feature Availability
This feature is only available in plans that include Full API access i.e Business and Growth.
Similar to the Export HTML function, you can also export a design as a ZIP file. This generates a bundle ZIP file that also includes all the images required by your design and uploads it to your connected File Storage.
Note: Unlike HTML or plain text, ZIP file is not generated on the client. This function uses our cloud API to generate the ZIP file.
unlayer.exportZip(function(data) {
var json = data.design; // design json
var fileUrl = data.url; // zip file url
// Do something with the ZIP url
})
Callback Parameters
The exportZip callback returns the following parameters.
Name | Description |
---|---|
design | This is the JSON of the design |
url | This is the URL of the generated ZIP file |
Export Options
You can also pass certain options to this function as a second parameter.
Merge Tags
If you want the Merge Tags in your design to be replaced by different values, you can pass the mergeTags
object to export options.
unlayer.exportZip(function(data) {
var json = data.design; // design json
var fileUrl = data.url; // zip file url
}, {
mergeTags: {
first_name: 'John',
last_name: 'Doe'
}
})
REST API
If you want to generate the ZIP file on the server-side, you can use our REST Export API.
const fetch = require('node-fetch');
let url = 'https://api.unlayer.com/v2/export/zip';
let options = {
method: 'POST',
headers: {'Content-Type': 'application/json', Authorization: 'Basic BASE64-ENCODED-API-KEY'},
body: JSON.stringify({
displayMode: 'email',
design: {}, // json of your design
mergeTags: {first_name: 'John', last_name: 'Doe'}
})
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
Learn more at Export API documentation.
Response
The API response will return an uploaded zip file URL.
{
"success": true,
"data": {
"url": "https://.../1593082715347-8LCcNZuuBpU4D92W.zip"
}
}
Updated about 3 years ago