Unlayer Cloud API (2)
Download OpenAPI specification:Download
Welcome to the Unlayer REST API documentation. Our API enables you to programmatically access and manipulate email templates, designs, and other Unlayer resources.
The Unlayer API uses Basic Authentication. All requests require you to authenticate using a Unlayer Project API Key as the username
with an empty string as the password
:
curl -u YOUR_API_KEY: -X GET https://api.unlayer.com/v2/templates
All API calls must use HTTPS. Any calls made using HTTP will return an appropriate error code.
Follow these steps to get your API key:
- Log in to the Developer Console
- Create a Project
- Find your API key in Project > Settings
Authorization: Basic BASE64-ENCODED-API-KEY
If you need to, you may construct and send basic auth headers yourself. To do this you need to perform the following steps:
- Get the API Key
- Build a string in the form of
APIKey:Password
where Password will always be empty. For example, if your API Key isXAyAztva4
, you will just add a:
at the end.XAyAztva4:
- Base64 encode the string
- Supply an
Authorization
header with contentBasic
followed by the encoded string. For example, the stringXAyAztva4:
encodes toWEF5QXp0dmE0Og==
in base64. Here's how the request would look:
curl -D- \
-X GET \
-H "Authorization: Basic WEF5QXp0dmE0Og==" \
"https://api.unlayer.com/v2/templates"
All API requests will receive a standard HTTP response code.
Response Ranges
- 2xx -- Successful Request
- 4xx -- Failed Request (Client error)
- 5xx -- Failed Request (Server error)
/templates
GET https://api.unlayer.com/v2/templates
Get a list of available templates
Authorizations:
query Parameters
page | integer >= 1 Default: 1 Current page |
perPage | integer >= 1 Default: 10 Number of templates to fetch per page |
includeDesign | integer Default: 1 Enum: 0 1 Should the result include design json or not. This is not recommended as it could result in long response. To disable, pass 0. |
Responses
Response samples
- 200
{- "success": true,
- "data": [
- {
- "id": "string",
- "name": "string",
- "design": { },
- "displayMode": "string",
- "updatedAt": "string",
- "createdAt": "string"
}
]
}
/templates/:id
GET https://api.unlayer.com/v2/templates/{id}
Get a specific template by ID
path Parameters
id required | string ID of the template to retrieve |
Responses
Response samples
- 200
{- "success": true,
- "data": {
- "id": "string",
- "name": "string",
- "design": { },
- "displayMode": "string",
- "updatedAt": "string",
- "createdAt": "string"
}
}
You can use Unlayer's Cloud API to generate HTML, Image, PDF or ZIP file of your templates or designs.
The Cloud API helps you take care these common use-cases:
- Retrieving the HTML: This is useful if you do not store the HTML, or need to retrieve the latest HTML for a design.
- Generating a Image: This is useful to show thumbnails or previews of designs to users.
- Generating a PDF: You can use this to export a design in PDF format.
- Generating a ZIP: This will export a design as a ZIP file that will include their html and images.
/export/html
POST https://api.unlayer.com/v2/export/html
Export a design to HTML format with various options
Authorizations:
Request Body schema: application/jsonrequired
design required | object The design JSON to export |
displayMode required | string Enum: "email" "web" "popup" The display mode of the design |
mergeTags | object Values to replace merge tags in the design |
customJS | Array of strings URLs to your custom JS to support custom tools |
Responses
Request samples
- Payload
{- "design": { },
- "displayMode": "email",
- "mergeTags": { },
- "customJS": [
- "string"
]
}
Response samples
- 200
{- "success": true,
- "data": {
- "html": "string",
- "chunks": {
- "body": "string",
- "css": "string",
- "js": "string",
- "fonts": [
- "string"
]
}
}
}
/export/image
POST https://api.unlayer.com/v2/export/image
Export a design to image format (PNG)
Authorizations:
Request Body schema: application/jsonrequired
design required | object The design JSON to export |
displayMode required | string Enum: "email" "web" "popup" The display mode of the design |
mergeTags | object Values to replace merge tags in the design |
customJS | Array of strings URLs to your custom JS to support custom tools |
fullPage | boolean Default: true Generate image of the full page. |
Responses
Request samples
- Payload
{- "design": { },
- "displayMode": "email",
- "mergeTags": { },
- "customJS": [
- "string"
], - "fullPage": true
}
Response samples
- 200
{- "success": true,
- "data": {
- "url": "string"
}
}
/export/pdf
POST https://api.unlayer.com/v2/export/pdf
Export a design to PDF format
Authorizations:
Request Body schema: application/jsonrequired
design required | object The design JSON to export |
displayMode required | string Enum: "email" "web" "popup" The display mode of the design |
mergeTags | object Values to replace merge tags in the design |
customJS | Array of strings URLs to your custom JS to support custom tools |
Responses
Request samples
- Payload
{- "design": { },
- "displayMode": "email",
- "mergeTags": { },
- "customJS": [
- "string"
]
}
Response samples
- 200
{- "success": true,
- "data": {
- "url": "string"
}
}
/export/zip
POST https://api.unlayer.com/v2/export/zip
Export a design as a ZIP archive containing all assets
Authorizations:
Request Body schema: application/jsonrequired
design required | object The design JSON to export |
displayMode required | string Enum: "email" "web" "popup" The display mode of the design |
mergeTags | object Values to replace merge tags in the design |
customJS | Array of strings URLs to your custom JS to support custom tools |
Responses
Request samples
- Payload
{- "design": { },
- "displayMode": "email",
- "mergeTags": { },
- "customJS": [
- "string"
]
}
Response samples
- 200
{- "success": true,
- "data": {
- "url": "string"
}
}