Themes
This endpoint is useful for working with Mautic Themes.
Using Mautic’s API Library
You can interact with this API through the Mautic API Library as follows, or use the various http endpoints as described in this document.
<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = "https://mautic.example.com";
$api = new MauticApi();
$themesApi = $api->newApi("themes", $auth, $apiUrl);
Get Theme
Returns directly the ZIP file in the response with the application/ZIP
header on success or a JSON response body with error messages on fail. The PHP API library saves the ZIP file to the system’s temporary directory and provides you with the path.
<?php
$response = $themesApi->get($themeName);
{
"file": "/absolute/path/to/the/system/temp/dir/with/the/theme/ZIP/file"
}
HTTP Request
GET /themes/THEME_NAME
Response
Expected Response Code: 200
Set Temporary File Path
Changes the default temporary directory where the ZIP file gets created. The directory gets created if it doesn’t exist.
<?php
$themesApi->setTemporaryFilePath("/absolute/path/to/a/different/temp/dir");
$response = $themesApi->get($themeName);
{
"file": "/absolute/path/to/a/different/temp/dir/ZIPfile"
}
Get List of Themes
Lists all installed Themes with the details stored in their config.json
files.
<?php
$response = $themesApi->getList();
HTTP Request
GET /themes
Response
Expected Response Code: 200
{
"themes": {
"blank": {
"name": "Blank",
"key": "blank",
"config": {
"name": "Blank",
"author": "Mautic team",
"authorUrl": "https:\/\/mautic.org",
"features": [
"page",
"email",
"form"
]
}
}
}
}
Response Properties
Name |
Type |
Description |
---|---|---|
|
array |
List of installed Themes and their configs |
Create Theme
Creates a new Theme or updates an existing one, based on the filename of the provided ZIP file.
<?php
$data = array(
'file' => dirname(__DIR__).'/'.'mytheme.ZIP' // Must be a path to an existing file
);
$response = $themeApi->create($data);
The file gets sent through a regular POST files array like a browser sends it during file upload.
HTTP Request
POST /themes/new
Response
Expected Response Code: 200
{
"success": true
}
Delete File
<?php
$response = $themeApi->delete($themeName);
Delete a Theme. You can’t delete stock Themes.
HTTP Request
DELETE /themes/THEME_NAME/delete
Response
Expected Response Code: 200
{
"success": true
}