« Back to Documentation Overview

templates – 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.

Section
Template Related
Parameters
apikey a valid API Key for your user account. Get by visiting your API dashboard
types optional - the types of templates to return
booleanuserCustom templates for this user account. Defaults to true.
booleangalleryTemplates from our Gallery. Note that some templates that require extra configuration are withheld. (eg, the Etsy template). Defaults to false.
booleanbaseOur "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
booleanincludeuser templates are not deleted, only set inactive. defaults to false.
booleanonlyonly include inactive templates. defaults to false.
Returns
array An array of arrays, one for each template
intidId of the template
stringnameName of the template
stringlayoutLayout of the template - "basic", "left_column", "right_column", or "postcard"
stringpreview_imageIf 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
stringdate_createdThe date/time the template was created
booleanedit_sourceWhether or not you are able to edit the source of a template.

Examples (2)

download example code

[1] mcapi_templates.php

  1. <?php
  2. /**
  3. This Example shows how to retrieve a list of your Campaign Templates
  4. via the MCAPI class.
  5. **/
  6. require_once 'inc/MCAPI.class.php';
  7. require_once 'inc/config.inc.php'; //contains apikey
  8.  
  9. $api = new MCAPI($apikey);
  10.  
  11. $types = array('user'=>true, 'gallery'=>true);
  12. $retval = $api->templates($types);
  13.  
  14. if ($api->errorCode){
  15. echo "Unable to Load Templates!";
  16. echo "\n\tCode=".$api->errorCode;
  17. echo "\n\tMsg=".$api->errorMessage."\n";
  18. } else {
  19. var_dump($retval);
  20. echo "Your templates:\n";
  21. foreach($retval['user'] as $tmpl){
  22. echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n";
  23. }
  24. echo "Gallery templates:\n";
  25. foreach($retval['gallery'] as $tmpl){
  26. echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n";
  27. }
  28. }
  29.  
  30. ?>
  31.  

[2] xml-rpc_templates.php

  1. <?php
  2. /**
  3. This Example shows how to Retrieve all of your Campaign Templates using the XML-RPC service
  4. and do some basic error checking.
  5. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. require_once 'inc/config.inc.php';
  9. try {
  10. $client = XML_RPC2_Client::create($apiUrl);
  11.  
  12. $types = array('user'=>true, 'gallery'=>true);
  13. $result = $client->campaignTemplates($apikey, $types);
  14. echo "SUCCESS! \n";
  15. echo "Your templates:\n";
  16. foreach($result['user'] as $tmpl){
  17. echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n";
  18. }
  19. echo "Gallery templates:\n";
  20. foreach($result['gallery'] as $tmpl){
  21. echo $tmpl['id']." | ".$tmpl['name']." | ".$tmpl['layout']."\n";
  22. }
  23. } catch (XML_RPC2_FaultException $e){
  24. echo "ERROR!!!!\n";
  25. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  26. }
  27. echo "\n";
  28.  
  29. ?>
  30.