Overview
  • Namespace
  • Class

Namespaces

  • MailChimp
    • AuthorizedApps
    • Automations
    • Batches
    • CampaignFolders
    • Campaigns
    • Conversations
    • Ecommerce
    • FileManager
    • Lists
    • Reports
    • TemplateFolders
    • Templates

Classes

  • MailChimp\AuthorizedApps\AuthorizedApps
  • MailChimp\Automations\Automations
  • MailChimp\Batches\Batches
  • MailChimp\CampaignFolders\CampaignFolders
  • MailChimp\Campaigns\Campaigns
  • MailChimp\Campaigns\Content
  • MailChimp\Campaigns\Feedback
  • MailChimp\Conversations\Conversations
  • MailChimp\Ecommerce\Carts
  • MailChimp\Ecommerce\Customers
  • MailChimp\Ecommerce\Ecommerce
  • MailChimp\Ecommerce\Orders
  • MailChimp\Ecommerce\Products
  • MailChimp\FileManager\Files
  • MailChimp\FileManager\Folders
  • MailChimp\Lists\Interests
  • MailChimp\Lists\Lists
  • MailChimp\Lists\Members
  • MailChimp\Lists\MergeFields
  • MailChimp\Lists\Segments
  • MailChimp\Lists\SignupForms
  • MailChimp\Lists\Webhooks
  • MailChimp\MailChimp
  • MailChimp\Reports\Reports
  • MailChimp\TemplateFolders\TemplateFolders
  • MailChimp\Templates\Templates
  1 <?php
  2 namespace MailChimp\Campaigns;
  3 
  4 use MailChimp\MailChimp as MailChimp;
  5 use MailChimp\Campaigns\Content as Content;
  6 use MailChimp\Campaigns\Feedback as Feedback;
  7 
  8 class Campaigns extends MailChimp
  9 {
 10 
 11     /**
 12      * Get a list of campaigns for the account
 13      *
 14      * Available query fields:
 15      * array["fields"]              array       list of strings of response fields to return
 16      * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 17      * array["count"]               int         number of records to return
 18      * array["offset"]              int         number of records from a collection to skip.
 19      * array["folder_id"]           string      Filter results by a specific campaign folder.
 20      * array["type"]                string      The campaign type.
 21      *                                          Possible values: regular,plaintext,absplit,rss,variate
 22      * array["status"]              string      The status of the campaign.
 23      *                                          Possible Values: save,paused,schedule,sending,sent
 24      * array["before_send_time"]    string      Restrict the response to campaigns sent before the set time.
 25      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 26      * array["since_send_time"]     string      Restrict the response to campaigns sent after the set time.
 27      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 28      * array["before_create_time"]  string      Restrict the response to campaigns sent after the set time.
 29      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 30      * array["since_create_time"]   string      Restrict the response to campaigns created after the set time.
 31      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 32      *
 33      * @param array $query (See Above) OPTIONAL associative array of query parameters.
 34      * @return object
 35      */
 36     public function getCampaigns(array $query = [])
 37     {
 38         return self::execute("GET", "campaigns", $query);
 39     }
 40 
 41     /**
 42      * Get a single campaign
 43      *
 44      * array["fields"]              array       list of strings of response fields to return
 45      * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 46      *
 47      * @param string $campaign_id for the campaign instance
 48      * @param array $query (See Above) OPTIONAL associative array of query parameters.
 49      * @return object
 50      */
 51     public function getCampaign($campaign_id, array $query = [])
 52     {
 53         return self::execute("GET", "campaigns/{$campaign_id}", $query);
 54     }
 55 
 56     /**
 57      * Review the send checklist for a campaign, and resolve any issues before sending.
 58      *
 59      * array["fields"]              array       list of strings of response fields to return
 60      * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 61      *
 62      * @param string $campaign_id for the campaign instance
 63      * @param array $query (See Above) OPTIONAL associative array of query parameters.
 64      * @return object
 65      */
 66     public function getCampaignChecklist($campaign_id, array $query = [])
 67     {
 68         return self::execute("GET", "campaigns/{$campaign_id}/send-checklist", $query);
 69     }
 70 
 71     /**
 72      * Create a campaign
 73      *
 74      * Example Request Body:
 75      *      "type"                          string      REQUIRED The campaign type. Possible Values: regular, plaintext, variate, rss
 76      *      "recipients"                    array       List setting for the campaign
 77      *          ["list_id"]                 string      REQUIRED The unique list id from lists()->getLists()
 78      *          ["segment_opts"]            array       optional segmentation options
 79      *               ["saved_segment_id"]   int         The id for an existing saved segment from lists()->segments()->getListSegments($listId)
 80      *               ["match"]              string      Segement match type. Possible Values: any, all
 81      *               ["conditions"]         array       An array of segment conditions
 82      *                                                  Structure depends on segment http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/#
 83      *      "settings"                      array       REQUIRED
 84      *          ["subject_line"]            string      REQUIRED The subject line for the campaign.
 85      *          ["title"]                   string      The title of the campaign.
 86      *          ["from_name"]               string      REQUIRED The ‘from’ name on the campaign (not an email address).
 87      *          ["reply_to"]                string      REQUIRED The reply-to email address for the campaign.
 88      *          ["use_conversation"]        boolean     Use MailChimp Conversation feature to manage out-of-office replies.
 89      *          ["to_name"]                 string      The campaign’s custom ‘To’ name. Typically the first name merge field.
 90      *          ["folder_id"]               string      If the campaign is listed in a folder, the id for that folder.
 91      *          ["authenticate"]            boolean     Whether MailChimp authenticated the campaign. Defaults to true.
 92      *          ["auto_footer"]             boolean     Automatically append MailChimp’s default footer to the campaign.
 93      *          ["inline_css"]              boolean     Automatically inline the CSS included with the campaign content.
 94      *          ["auto_tweet"]              boolean     Automatically tweet a link to the campaign archive page when the campaign is sent.
 95      *          ["auto_fb_post"]            array       An array of Facebook page ids to auto-post to.
 96      *          ["fb_comments"]             boolean     Allows Facebook comments on the campaign (also force-enables the Campaign Archive toolbar).
 97      *                                                  Defaults to true.
 98      *      "optional_settings"              array       associative array of optional/conditional campaign options.
 99      *          ["variate_settings"]        array       Required if type "variate" is set. The settings specific to variate campaigns.
100      *               ["winner_criteria"]    string      Required is variate. Possible Values: opens,clicks,manual, total_revenue
101      *               ["wait_time"]          int         The number of minutes to wait before choosing the winning campaign.
102      *                                                  The value of wait_time must be greater than 0 and in whole hours, specified in minutes.
103      *               ["test_size"]          int         The percentage of recipients to send the test combinations to, must be a value between 10 and 100.
104      *               ["subject_lines"]      array       The possible subject lines to test. If no subject lines are provided, settings.subject_line will be used.
105      *               ["send_times"]         array       The possible send times to test. The times provided should be in the format YYYY-MM-DD HH:MM:SS. If send_times are provided to test, the test_size will be set to 100% and winner_criteria will be ignored.
106      *               ["from_names"]         array       The possible from names. The number of from_names provided must match the number of reply_to_addresses. If no from_names are provided, settings.from_name will be used.
107      *               ["reply_to_addresses"] array       The possible reply-to addresses. The number of reply_to_addresses provided must match the number of from_names. If no reply_to_addresses are provided, settings.reply_to will be used.
108      *          ["rss_opts"]                array       Required if type "rss" is set. The settings specific to rss campaigns.
109      *               ["feed_url"]           string      Required for rss. The URL for the RSS feed.
110      *               ["frequency"]          string      Required for rss. The frequency of the RSS Campaign. Possible Values: daily,weekly,monthly
111      *               ["schedule"]           array       The schedule for sending the RSS Campaign.
112      *                  ["hour"]            int         The hour to send the campaign in local time. Acceptable hours are 0-23. For example, ‘4’ would be 4am in your account’s default time zone.
113      *                  ["daily_send"]      array       The days of the week to send a daily RSS Campaign.
114      *                      ["sunday"]      boolean
115      *                      ["monday"]      boolean
116      *                      ["tuesday"]     boolean
117      *                      ["wednesday"]   boolean
118      *                      ["thursday"]    boolean
119      *                      ["friday"]      boolean
120      *                      ["saturday"]    boolean
121      *                  ["weekly_send_day"] string      The day of the week to send a weekly RSS Campaign.
122      *                                                  Possible Values:sunday,monday,tuesday,wednesday,thursday,friday,saturday
123      *                  ["monthly_send_date"]   number   The day of the month to send a monthly RSS Campaign.
124      *                                                  Acceptable days are 1-31, where ‘0’ is always the last day of a month
125      *               ["constrain_rss_img"]  boolean     Whether to add CSS to images in the RSS feed to constrain their width in campaigns.
126      *          ["tracking"]                array       Required if type variate is set. The settings specific to variate campaigns.
127      *               ["opens"]              boolean
128      *               ["html_clicks"]        boolean
129      *               ["text_clicks"]        boolean
130      *               ["goal_tracking"]      boolean
131      *               ["ecomm360"]           boolean
132      *               ["google_analytics"]   string      The custom slug for Google Analytics tracking (max of 50 bytes).
133      *               ["clicktale"]          string      The custom slug for ClickTale tracking (max of 50 bytes).
134      *               ["salesforce"]         array       Salesforce tracking options for a campaign.
135      *                                                  Must be using MailChimp’s built-in Salesforce integration.
136      *                    ["campaign"]      boolean     Create a campaign in a connected Salesforce account.
137      *                    ["notes"]         boolean     Update contact notes for a campaign based on subscriber email addresses.
138      *               ["highrise"]           array
139      *                    ["campaign"]      boolean     Create a campaign in a connected Highrise account.
140      *                    ["notes"]         boolean     Update contact notes for a campaign based on subscriber email addresses.
141      *               ["capsule"]            array
142      *                    ["notes"]         boolean     Update contact notes for a campaign based on subscriber email addresses.
143      *          ["social_cards"]            array       Required if type variate is set. The settings specific to rss campaigns.
144      *               ["image_url"]          string      The url for the header image for the card.
145      *               ["description"]        string      A short summary of the campaign to display.
146      *               ["title"]              string      The title for the card.
147      * @param array $type       Required
148      * @param array $recipients Required
149      * @param array $settings   Required
150      * @param array $optional_settings (See possible values above)
151      * @return object
152      */
153     public function createCampaign($type, array $recipients = [], array $settings = [], array $optional_settings = null )
154     {
155         $optional_fields = ["tracking", "social_card", "variate_settings", "rss_opts"];
156 
157         $data = [
158             "type" => $type,
159             "recipients" => $recipients,
160             "settings" => $settings
161         ];
162 
163         // If the optional fields are passed, process them against the list of optional fields.
164         if (isset($optional_settings)) {
165             $data = array_merge($data, self::optionalFields($optional_fields, $optional_settings));
166         }
167 
168         return self::execute("POST", "campaigns", $data);
169     }
170 
171     /**
172      * Update a Campaign
173      *
174      * @param string $campaign_id for the campaign instance
175      * @param array $data
176      * @return object
177      */
178     public function updateCampaign($campaign_id, array $data = [])
179     {
180         return self::execute("PATCH", "campaigns/{$campaign_id}", $data);
181     }
182 
183     /**
184      * Pause an RSS-Driven campaign
185      *
186      * @param string $campaign_id for the campaign instance
187      */
188     public function pauseRSSCampaign($campaign_id)
189     {
190         return self::execute("POST", "campaigns/{$campaign_id}/actions/pause");
191     }
192 
193     /**
194      * Resume an RSS-Driven campaign
195      *
196      * @param string $campaign_id for the campaign instance
197      */
198     public function resumeRSSCampaign($campaign_id)
199     {
200         return self::execute("POST", "campaigns/{$campaign_id}/actions/resume");
201     }
202 
203     /**
204      * Replicate a campaign
205      *
206      * @param string $campaign_id for the campaign instance
207      */
208     public function replicateCampaign($campaign_id)
209     {
210         return self::execute("POST", "campaigns/{$campaign_id}/actions/replicate");
211     }
212 
213 
214     /**
215      * Cancel a campaign
216      *
217      * @param string $campaign_id for the campaign instance
218      */
219     public function cancelCampaign($campaign_id)
220     {
221         return self::execute("POST", "campaigns/{$campaign_id}/actions/cancel-send");
222     }
223 
224     /**
225      * Schedule a campaign
226      *
227      * @param string $campaign_id for the campaign instance
228      */
229     public function scheduleCampaign($campaign_id)
230     {
231         return self::execute("POST", "campaigns/{$campaign_id}/actions/schedule");
232     }
233 
234     /**
235      * Unschedule a campaign
236      *
237      * @param string $campaign_id for the campaign instance
238      */
239     public function unscheduleCampaign($campaign_id)
240     {
241         return self::execute("POST", "campaigns/{$campaign_id}/actions/unschedule");
242     }
243 
244     /**
245      * Send a test email
246      *
247      * @param string $campaign_id for the campaign instance
248      */
249     public function sendCampaignTest($campaign_id)
250     {
251         return self::execute("POST", "campaigns/{$campaign_id}/actions/test");
252     }
253 
254     /**
255      * Send a campaign
256      *
257      * @param string $campaign_id for the campaign instance
258      */
259     public function sendCampaign($campaign_id)
260     {
261         return self::execute("POST", "campaigns/{$campaign_id}/actions/send");
262     }
263 
264     /**
265      * Delete a campaign
266      *
267      * @param string $campaign_id for the campaign instance
268      */
269     public function deleteCampaign($campaign_id)
270     {
271         return self::execute("DELETE", "campaigns/{$campaign_id}/");
272     }
273 
274     /**
275      *  Instantiates the Content class.
276      *
277      */
278      public function content()
279      {
280          return new Content;
281      }
282 
283      /**
284       *  Instantiates the Feedback class.
285       *
286       */
287       public function feedback()
288       {
289           return new Feedback;
290       }
291 
292 
293 
294 
295 }
296 
API documentation generated by ApiGen