REST API v4: POST template

This method is used to create a new template with the REST API. It uses an HTTP POST request to the following address:

https://api.copernica.com/v4/draganddrop/template

Available parameters

  • name: name of the new template to be created (required)
  • description: optional description of the template
  • from_address: object with the following properties:
    • name: the sender's name
    • address: the sender's email address
  • source: object with the following properties:
    • html: the HTML source code of the template
    • text: the plain text version of the template
  • language: the language of the template
  • timezone: the timezone of the template
  • reply to: the reply-to address of the template
  • bcc: the BCC address of the template
  • archived: optional boolean value to immediately archive the template
  • unsubscribe_header: indicates whether an unsubscribe header should be included. Possible values: both (default), email, link, or no.

JSON example

The following JSON demonstrates how to use the API method:

{
    "name": "Test template",
    "description": "This is a test template",
    "from_address": {
        "name": "Support",
        "address": "support@yourdomain.com"
    },
    "subject": "This is a test",
    "archived": false,
    "source": {
        "html": "<html><body>This is a test template</body></html>",
        "text": "This is a text version"
    },
    "language": "nl_NL",
    "timezone": "Europe/Amsterdam",
    "unsubscribe_header": "both"
}

PHP example

The following PHP script demonstrates how to use the API method:

// dependencies
require_once('copernica-rest-api.php');

// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 4);

// data to be sent to the api
$data = array(
    'name'                  => 'Test template',
    'description'           => 'This is a test template',
    'from_address'          => array(
        'name'              => 'Support',
        'address'           => 'support@yourdomain.com'
    ),
    'subject'               => 'This is a test',
    'archived'              => false,
    'source'                => array( 
        'html'              => '<html><body>This is a test template</body></html>', 
        'text'              => 'This is a text version' ),
    'language'              => 'nl_NL',
    'timezone'              => 'Europe/Amsterdam',
    'unsubscribe_header'    => 'both'
);

// do the call
$api->post("draganddrop/template", $data);

The example above requires the CopernicaRestApi class.