Templates

Templates endpoints of the MailWizz API.

Templates endpoint

// CREATE THE ENDPOINT
$endpoint = new EmsApi\Endpoint\Templates();
# CREATE THE ENDPOINT
endpoint = Templates.new
from mailwizz.endpoint.templates import Templates

"""
CREATE THE ENDPOINT
"""
endpoint = Templates()

Get all templates

// GET ALL ITEMS
$response = $endpoint->getTemplates($pageNumber = 1, $perPage = 10);

// DISPLAY RESPONSE
echo '<pre>';
print_r($response->body);
echo '</pre>';
# GET ALL TEMPLATES
response = endpoint.get_templates(page = 1, per_page = 10)

# DISPLAY RESPONSE
puts response.body
"""
GET ALL TEMPLATES
"""
response = endpoint.get_templates(page=1, per_page=10)

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success",
  "data": {
    "records": [
      {
        "template_uid": "xxxxxxxxx",
        "name": "portfolio_html (1)",
        "screenshot": "https:\/\/domain.com\/frontend\/assets\/gallery\/ew055sq9tn97e\/img_ytStill.png"
     }
    ]
  }
}

This endpoint retrieves all the templates.

HTTP Request

GET API-URL/templates

Query Parameters

ParameterDefaultDescription
page1Current page to retrieve.
per_page10Items per page to retrieve.

Get one template

// GET ONE ITEM
$response = $endpoint->getTemplate('TEMPLATE-UNIQUE-ID');

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
# GET ONE ITEM
response = endpoint.get_template(template_uid = 'TEMPLATE-UNIQUE-ID')

# DISPLAY RESPONSE
puts response.body
"""
GET ONE ITEM
"""
response = endpoint.get_template(template_uid='TEMPLATE-UNIQUE-ID')

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success",
  "data": {
    "record": {
      "name": "portfolio_html (1)",
      "content": "HTML content...",
      "screenshot": "https:\/\/domain.com\/frontend\/assets\/gallery\/ew055sq9tn97e\/img_ytStill.png"
    }
  }
}

This endpoint retrieves the template with the given TEMPLATE-UNIQUE-ID.

HTTP Request

GET API-URL/templates/TEMPLATE-UNIQUE-ID

URL Segments

SegmentRequiredDescription
TEMPLATE-UNIQUE-IDyesTemplate unique id which to retrieve.

Search templates

// Search ALL ITEMS (available from MailWizz 1.4.4)
$response = $endpoint->searchTemplates($pageNumber = 1, $perPage = 10, [
    'name' => 'my template name'
]);

// DISPLAY RESPONSE
echo '<pre>';
print_r($response->body);
echo '</pre>';
# SEARCH FOR TEMPLATES
response = endpoint.search_templates(page = 1, per_page = 10, filters = {
    'name': 'example-template'
})

# DISPLAY RESPONSE
puts response.body
"""
SEARCH FOR TEMPLATES
"""
response = endpoint.search_templates(page=1, per_page=10, filters={
    'name': 'example-template'
})

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success",
  "data": {
    "records": [
      {
      "name": "portfolio_html (1)",
      "content": "HTML content...",
      "screenshot": "https:\/\/domain.com\/frontend\/assets\/gallery\/ew055sq9tn97e\/img_ytStill.png"
     }
    ]
  }
}

This endpoint retrieves the templates based on the filter keys values.

HTTP Request

GET API-URL/templates

Query Parameters

ParameterTypeRequired/DefaultDescription
pageint1Current page to retrieve.
per_pageint10Items per page to retrieve.
filtersarrayyesIndexed array having template attributes as keys.(i.e.: name )

Create a template

// CREATE A NEW TEMPLATE
$rand = rand();
$response = $endpoint->create([
    'name'          => 'My API template ' . $rand,
    'content'       => file_get_contents(__DIR__ . '/template-example.html'),
    //'archive'     => file_get_contents(__DIR__ . '/template-example.zip'),
    'inline_css'    => 'no',// yes|no
]);

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
# CREATE ONE TEMPLATE
response = endpoint.create(data = {
    'name': 'My API template ',
    # 'content': '<body>Hello</body>',
    # 'content': File.read('template-example.html'),
    # 'archive': File.read('template-example.zip'), - TODO - Request entity too large for zip in all the endpoints
    'inline_css': 'no', # yes|no
})

# DISPLAY RESPONSE
puts response.body
"""
CREATE ONE TEMPLATE
"""
response = endpoint.create(data={
    'name': 'My API template ',
    # 'content': '<body>Hello</body>',
    # 'content': open('template-example.html', 'r').read(),
    'archive': open('template-example.zip', 'rb').read(),
    'inline_css': 'no',  # yes|no
})

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success",
  "template_uid": "jo441taeq281e"
}

This endpoint creates a template.

HTTP Request

POST API-URL/templates

POST Parameters

ParameterTypeRequiredDescription
templatearrayyesArray with the template details.

Data block - required

ParameterTypeRequiredDescription
namestringyesTemplate name
contentstringyesThe template content
archivestringnoZip archive name on the disk. This can be used when not using the plain content key
inline_cssYes/NonoAllow/disallow inline css

Update a template

// UPDATE A TEMPLATE
$response = $endpoint->update('TEMPLATE-UNIQUE-ID', [
    'name'          => 'My API template - updated' . $rand,
    'content'       => file_get_contents(__DIR__ . '/template-example.html'),
    //'archive'     => file_get_contents(__DIR__ . '/template-example.zip'),
    'inline_css'    => 'no',// yes|no
]);

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
# UPDATE ONE TEMPLATE
response = endpoint.update(template_uid = 'TEMPLATE-UNIQUE-ID', data = {
    'name': 'My API template - Updated',
    # 'content': open('template-example.html', 'rb').read(),
    # 'archive': open('template-example.zip', 'rb').read(),
    'inline_css': 'no', # yes|no
})

# DISPLAY RESPONSE
puts response.body
"""
UPDATE ONE TEMPLATE
"""
response = endpoint.update(template_uid='TEMPLATE-UNIQUE-ID', data={
    'name': 'My API template - Updated',
    # 'content': open('template-example.html', 'rb').read(),
    # 'archive': open('template-example.zip', 'rb').read(),
    'inline_css': 'no',  # yes|no
})

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success"
}

This endpoint updates a template.

HTTP Request

PUT API-URL/templates/TEMPLATE-UNIQUE-ID

URL Segments

SegmentRequiredDescription
TEMPLATE-UNIQUE-IDyesTemplate unique identifier

PUT Parameters

ParameterTypeRequiredDescription
dataarrayyesArray with the template details. See the create section for details

Delete a template

// delete template
$response = $endpoint->delete('TEMPLATE-UNIQUE-ID');

// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';
# DELETE A TEMPLATE
response = endpoint.delete('TEMPLATE-UNIQUE-ID')

# DISPLAY RESPONSE
puts response.body
"""
DELETE A TEMPLATE
"""
response = endpoint.delete('TEMPLATE-UNIQUE-ID')

"""
DISPLAY RESPONSE
"""
print(response.content)

The above command returns an object structured like this JSON:

{
  "status": "success"
}

This endpoint will delete the template with the given TEMPLATE-UNIQUE-ID.

HTTP Request

DELETE API-URL/templates/TEMPLATE-UNIQUE-ID

URL Segments

SegmentRequiredDescription
TEMPLATE-UNIQUE-IDyesTemplate unique id to delete.