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\Lists;
  3 
  4 class Segments extends Lists
  5 {
  6 
  7     /**
  8      * Get a list of campaigns for the account
  9      * Available query fields:
 10      * array["fields"]              array       list of strings of response fields to return
 11      * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 12      * array["count"]               int         number of records to return
 13      * array["offset"]              int         number of records from a collection to skip.
 14      * array["type"]                string      The campaign type.
 15      *                                          Possible values: saved,static,fuzzy
 16      * array["since_created_at"]    string      Restrict the response to campaigns created after the set time.
 17      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 18      * array["before_created_at"]   string      Restrict the response to segments created before the set time.
 19      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 20      * array["since_updated_at"]   string       Restrict the response to segments updated after the set time.
 21      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 22      * array["before_updated_at"]   string      Restrict the response to segments updated after the set time.
 23      *                                          ISO 8601 time format: 2015-10-21T15:41:36+00:00.
 24      * @param string $list_id
 25      * @param array $query (See Above) OPTIONAL associative array of query parameters.
 26      * @return object
 27      */
 28     public function getListSegments($list_id, array $query = [])
 29     {
 30         return self::execute("GET", "lists/{$list_id}/segments", $query);
 31     }
 32 
 33     /**
 34      * Get information about a specific segment.
 35      * Available query fields:
 36      * array["fields"]              array       list of strings of response fields to return
 37      * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 38      * @param string $list_id
 39      * @param string $segment_id
 40      * @param array $query (See Above) OPTIONAL associative array of query parameters.
 41      * @return object
 42      */
 43      public function getListSegment($list_id, $segment_id, array $query = [])
 44      {
 45          return self::execute("GET", "lists/{$list_id}/segments/{$segment_id}", $query);
 46      }
 47 
 48      /**
 49       * Get information about members in a saved segment.
 50       * Available query fields:
 51       * array["fields"]              array       list of strings of response fields to return
 52       * array["exclude_fields"]      array       list of strings of response fields to exclude (not to be used with "fields")
 53       * array["count"]               int         number of records to return
 54       * array["offset"]              int         number of records from a collection to skip.
 55       * @param string $list_id
 56       * @param string $segment_id
 57       * @param array $query (See Above) OPTIONAL associative array of query parameters.
 58       * @return object
 59       */
 60       public function getListSegmentMembers($list_id, $segment_id, array $query = [])
 61       {
 62           return self::execute("GET", "lists/{$list_id}/segments/{$segment_id}/members", $query);
 63       }
 64 
 65 
 66      /**
 67       * Create a new segment in a specific list.
 68       * array["data"]
 69       *      ["name"]               string     required
 70       *      ["static_segment"]     array       An array of emails to be used for a static segment.
 71       *                                         Any emails provided that are not present on the list will be ignored.
 72       *                                         Passing an empty array will create a static segment without any subscribers.
 73       *                                         This field cannot be provided with the options field.
 74       *     ["options"]             array       The conditions of the segment. Static and fuzzy segments don’t have conditions.
 75       *         ["match"]           string      Match Type Possible Values: any, all
 76       *         ["conditions"]      array       An array of segment conditions.
 77       *               Structure depends on segment http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/#
 78       * @param string $list_id
 79       * @param array $data
 80       * @return object
 81       */
 82      public function createListSegment($list_id, array $data =[])
 83      {
 84          return self::execute("POST", "lists/{$list_id}/segments", $data);
 85      }
 86 
 87      /**
 88       * Update a specific segment in a list.
 89       * Structure depends on segment http://developer.mailchimp.com/documentation/mailchimp/reference/lists/segments/#
 90       * @param string $list_id
 91       * @param array $data
 92       * @return object
 93       */
 94      public function updateListSegment($list_id, $segment_id, array $data = null)
 95      {
 96          return self::execute("PATCH", "lists/{$list_id}/segments/{$segment_id}", $data);
 97      }
 98 
 99      /**
100      * Add a member to a static segment.
101      * array["data"]
102      *      ["email_address"]      string     required
103       * @param string $list_id
104       * @param array $data
105       * @return object
106       */
107      public function addListSegmentMember($list_id, $segment_id, $email_address, array $data =[])
108      {
109          return self::execute("POST", "lists/{$list_id}/segments/{$segment_id}/members", $data);
110      }
111 
112      /**
113      * Batch add/remover members to a static segment.
114      * array["emails"]
115      *      ["add"]      array
116      *      ["remove"]      array
117       * @param string $list_id
118       * @param string $segment_id
119       * @param array $emails
120       * @return object
121       */
122      public function batchAddRemoveSegmentMembers($list_id, $segment_id, array $emails = [])
123      {
124          if (isset($emails["add"])) {
125              $data["members_to_add"] = $emails["add"];
126          }
127 
128          if (isset($emails["remove"])) {
129             $data["members_to_remove"] = $emails["remove"];
130         }
131         // print_r ($data);
132          return self::execute("POST", "lists/{$list_id}/segments/{$segment_id}", $data);
133      }
134 
135 
136      /**
137       * Remove a member from the specified static segment.
138       * @param string $list_id
139       * @param string $segment_id
140       * @param string $email_address
141       */
142       public function removeListSegmentMember($list_id, $segment_id, $email_address)
143       {
144           $hash = self::getMemberHash($email_address);
145           return self::execute("DELETE", "lists/{$list_id}/segments/{$segment_id}/members/{$hash}");
146       }
147 
148      /**
149       * Delete a specific segment in a list.
150       * @param string $list_id
151       * @param string $segment_id
152       */
153       public function deleteListSegment($list_id, $segment_id)
154       {
155           return self::execute("DELETE", "lists/{$list_id}/segments/{$segment_id}");
156       }
157 
158 }
159 
API documentation generated by ApiGen