« Back to Documentation Overviewtemplates – v1.3
templates(string apikey, array types, array inactives, string category)
Retrieve various templates available in the system, allowing some thing similar to our template gallery to be created.
| Parameters | | apikey | a valid API Key for your user account. Get by visiting your API dashboard |
| types | optional - the types of templates to return| boolean | user | Custom templates for this user account. Defaults to true. | | boolean | gallery | Templates from our Gallery. Note that some templates that require extra configuration are withheld. (eg, the Etsy template). Defaults to false. | | boolean | base | Our "start from scratch" extremely basic templates. Defaults to false. |
|
| category | optional - for Gallery templates only, limit to a specific template category |
| inactives | optional - options to control how inactive templates are returned, if at all| boolean | include | user templates are not deleted, only set inactive. defaults to false. | | boolean | only | only include inactive templates. defaults to false. |
|
| Returns | | array |
An array of arrays, one for each template
| int | id | Id of the template
| | string | name | Name of the template
| | string | layout | Layout of the template - "basic", "left_column", "right_column", or "postcard"
| | string | preview_image | If we've generated it, the url of the preview image for the template. We do out best to keep these up to date, but Preview image urls are not guaranteed to be available
| | string | date_created | The date/time the template was created
| | boolean | edit_source | Whether or not you are able to edit the source of a template.
| |
Examples (2)
download example code
[1] mcapi_templates.php
<?php
/**
This Example shows how to retrieve a list of your Campaign Templates
via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$types = array('user'=>true
, 'gallery'=>true
); $retval = $api->templates($types);
if ($api->errorCode){
echo "Unable to Load Templates!"; echo "\n\tCode=".$api->errorCode; echo "\n\tMsg=".$api->errorMessage."\n"; } else {
echo "Your templates:\n"; foreach($retval['user'] as $tmpl){
echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n"; }
echo "Gallery templates:\n"; foreach($retval['gallery'] as $tmpl){
echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n"; }
}
?>
[2] xml-rpc_templates.php
<?php
/**
This Example shows how to Retrieve all of your Campaign Templates using the XML-RPC service
and do some basic error checking.
Note that we are using the PEAR XML-RPC client and recommend others do as well.
**/
require_once 'XML/RPC2/Client.php';
require_once 'inc/config.inc.php';
try {
$types = array('user'=>true
, 'gallery'=>true
); $result = $client->campaignTemplates($apikey, $types);
echo "Your templates:\n"; foreach($result['user'] as $tmpl){
echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n"; }
echo "Gallery templates:\n"; foreach($result['gallery'] as $tmpl){
echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n"; }
} catch (XML_RPC2_FaultException $e){
echo $e->getFaultCode()." : ".$e->getFaultString()."\n"; }
?>