« Back to Documentation Overview
campaignCreate – v1.3
campaignCreate(string apikey, string type, array options, array content, array segment_opts, array type_opts)
Create a new draft campaign to send. You can not have more than 32,000 campaigns in your account.
- <?php
- /**
- This Example shows how to create a basic campaign via the MCAPI class.
- **/
- require_once 'inc/MCAPI.class.php';
- require_once 'inc/config.inc.php'; //contains apikey
- $type = 'regular';
- $opts['list_id'] = 'f9ee6d8616';
- $opts['subject'] = 'Test Newsletter Subject';
- $opts['from_email'] = 'mailchimp@example.org';
- $opts['from_name'] = 'ACME, Inc.';
- $opts['authenticate'] = true;
- $opts['title'] = 'Test Newsletter Title';
- 'text' => 'text text text *|UNSUB|*'
- );
- /** OR we could use this:
- $content = array('html_main'=>'some pretty html content',
- 'html_sidecolumn' => 'this goes in a side column',
- 'html_header' => 'this gets placed in the header',
- 'html_footer' => 'the footer with an *|UNSUB|* message',
- 'text' => 'text content text content *|UNSUB|*'
- );
- $opts['template_id'] = "1";
- **/
- $retval = $api->campaignCreate($type, $opts, $content);
- if ($api->errorCode){
- } else {
- }
- ?>
- <?php
- /**
- This Example shows how create a basic campaign using XML-RPC.
- 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 {
- $type = 'regular';
- $opts['list_id'] = $listId;
- $opts['subject'] = 'hello thar!';
- $opts['from_email'] = $my_email;
- $opts['from_name'] = 'My Name';
- 'text_clicks' => false);
- $opts['authenticate'] = false;
- $opts['title'] = 'My 123 Campaign';
- 'text' => 'text text text *|UNSUB|*');
- $seg['match'] = 'any';
- $result = $client->campaignCreate($apikey, $type, $opts, $content, $seg);
- } catch (XML_RPC2_FaultException $e){
- }
- ?>
- <?php
- /**
- This Example shows how create an A/B Split campaign using XML-RPC.
- 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 {
- $opts['list_id'] = $listId;
- $opts['subject'] = 'hello thar!';
- $opts['from_email'] = $my_email;
- $opts['from_name'] = 'My Name';
- 'text_clicks' => false);
- $opts['authenticate'] = false;
- $opts['title'] = 'My 123 Campaign';
- 'text' => 'text text text *|UNSUB|*');
- //no segmentation on this one.
- $type = "absplit";
- $type_opts['split_test'] = 'schedule';
- $type_opts['pick_winner'] = 'manual';
- $type_opts['from_name_a'] = 'Wahoo McDaniels';
- $type_opts['from_email_a'] = 'wahoo@example.org';
- $type_opts['from_name_b'] = 'Yahoo McDonald';
- $type_opts['from_email_b'] = 'yahoo@example.org';
- $result = $client->campaignCreate($apikey, $type, $opts, $content, $seg, $type_opts);
- } catch (XML_RPC2_FaultException $e){
- }
- ?>
- <?php
- /**
- This Example shows how create a RSS campaign using XML-RPC.
- 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 {
- $opts['list_id'] = $listId;
- $opts['subject'] = 'hello thar!';
- $opts['from_email'] = $my_email;
- $opts['from_name'] = 'My Name';
- 'text_clicks' => false);
- $opts['authenticate'] = false;
- $opts['title'] = 'My 123 Campaign';
- 'text' => 'text text text *|UNSUB|*');
- //no segmentation on this one.
- $type = 'rss';
- $type_opts['url'] = 'http://mailchimp.com/blog/rss';
- $result = $client->campaignCreate($apikey, $type, $opts, $content, $seg, $type_opts);
- } catch (XML_RPC2_FaultException $e){
- }
- ?>
| Section | Campaign Related |
|---|
| Parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| apikey | a valid API Key for your user account. Get by visiting your API dashboard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type | the Campaign Type to create - one of "regular", "plaintext", "absplit", "rss", "auto" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options | a hash of the standard options for this campaign :
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content | the content for this campaign - use a struct with the following keys:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| segment_opts | optional - if you wish to do Segmentation with this campaign this array should contain: see campaignSegmentTest(). It's suggested that you test your options against campaignSegmentTest(). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type_opts | optional -
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns | |
|---|---|
| string | the ID for the created campaign |
Examples (4)
download example code[1] mcapi_campaignCreate.php
[2] xml-rpc_campaignCreate.php
[3] xml-rpc_campaignCreateABSplit.php
[4] xml-rpc_campaignCreateRss.php