@@ -11,6 +11,7 @@ class Lists extends KlaviyoAPI
1111 /**
1212 * List endpoint constants
1313 */
14+ const ENDPOINT_ALL = 'all ' ;
1415 const ENDPOINT_EXCLUSIONS = 'exclusions ' ;
1516 const ENDPOINT_GROUP = 'group ' ;
1617 const ENDPOINT_LIST = 'list ' ;
@@ -57,22 +58,40 @@ public function getLists() {
5758
5859 /**
5960 * Get information about a list
60- * @link https://www.klaviyo.com/docs/api/v2/lists#get-list
6161 *
62- * @param $listId
62+ * @deprecated 2.2.6
63+ * @see getListById
64+ *
65+ * @param string $listId
6366 * 6 digit unique identifier of the list
6467 *
6568 * @return bool|mixed
6669 */
6770 public function getListDetails ( $ listId )
6871 {
69- $ path = sprintf ( '%s/%s ' , self ::ENDPOINT_LIST , $ listId );
70- return $ this ->v2Request ( $ path );
72+ return $ this ->getListById ($ listId );
73+ }
74+
75+ /**
76+ * Get information about a list.
77+ * @link https://www.klaviyo.com/docs/api/v2/lists#get-list
78+ *
79+ * @param string $listId
80+ * 6 digit unique identifier of the list
81+ *
82+ * @return bool|mixed
83+ */
84+ public function getListById ($ listId )
85+ {
86+ $ path = sprintf ('%s/%s ' , self ::ENDPOINT_LIST , $ listId );
87+ return $ this ->v2Request ($ path );
7188 }
7289
7390 /**
7491 * Update a list's properties
75- * @link https://www.klaviyo.com/docs/api/v2/lists#put-list
92+ *
93+ * @deprecated 2.2.6
94+ * @see updateListNameById
7695 *
7796 * @param $listId
7897 * 6 digit unique identifier of the list
@@ -84,13 +103,30 @@ public function getListDetails( $listId )
84103 */
85104 public function updateListDetails ( $ listId , $ list_name )
86105 {
87- $ params = $ this ->createRequestBody ( array (
88- self ::LIST_NAME => $ list_name
89- ) );
106+ return $ this ->updateListNameById ($ listId , $ list_name );
107+ }
90108
91- $ path = sprintf ( '%s/%s ' , self ::ENDPOINT_LIST , $ listId );
109+ /**
110+ * Update a list's name.
111+ * @link https://www.klaviyo.com/docs/api/v2/lists#put-list
112+ *
113+ * @param string $listId
114+ * 6 digit unique identifier of the list
115+ *
116+ * @param string $listName
117+ * String to update list name to
118+ *
119+ * @return bool|mixed
120+ */
121+ public function updateListNameById ($ listId , $ listName )
122+ {
123+ $ params = $ this ->createRequestBody (
124+ array (self ::LIST_NAME => $ listName )
125+ );
126+
127+ $ path = sprintf ('%s/%s ' , self ::ENDPOINT_LIST , $ listId );
92128
93- return $ this ->v2Request ( $ path , $ params , self ::HTTP_PUT );
129+ return $ this ->v2Request ($ path , $ params , self ::HTTP_PUT );
94130 }
95131
96132 /**
@@ -110,7 +146,9 @@ public function deleteList( $listId )
110146
111147 /**
112148 * Subscribe or re-subscribe profiles to a list. Profiles will be single or double opted into the specified list in accordance with that list’s settings.
113- * @link https://www.klaviyo.com/docs/api/v2/lists#post-subscribe
149+ *
150+ * @deprecated 2.2.6
151+ * @see addSubscribersToList
114152 *
115153 * @param $listId
116154 * 6 digit unique identifier of the list
@@ -126,18 +164,40 @@ public function deleteList( $listId )
126164 */
127165 public function subscribeMembersToList ( $ listId , $ profiles )
128166 {
129- $ this ->checkProfile ( $ profiles );
167+ return $ this ->addSubscribersToList ($ listId , $ profiles );
168+ }
169+
170+ /**
171+ * Subscribe or re-subscribe profiles to a list. Profiles will be single or double opted into the specified list in accordance with that list’s settings.
172+ * @link https://www.klaviyo.com/docs/api/v2/lists#post-subscribe
173+ *
174+ * @param $listId
175+ * 6 digit unique identifier of the list
176+ *
177+ * @param array $profiles
178+ * The profiles that you would like to subscribe. Each object in the list must have either an email or phone number key.
179+ * You can also provide additional properties as key-value pairs. If you are a GDPR compliant business, you will need to include $consent in your API call.
180+ * $consent is a Klaviyo special property and only accepts the following values: "email", "web", "sms", "directmail", "mobile".
181+ * If you are updating consent for a phone number or would like to send an opt-in SMS to the profile (for double opt-in lists), include an sms_consent key in the profile with a value of true or false.
182+ *
183+ * @return bool|mixed
184+ * @throws Exception\KlaviyoException
185+ */
186+ public function addSubscribersToList ($ listId , $ profiles )
187+ {
188+ $ this ->checkProfile ($ profiles );
130189
131190 $ profiles = array_map (
132- function ( $ profile ) {
191+ function ($ profile ) {
133192 return $ profile ->toArray ();
134- }, $ profiles
193+ },
194+ $ profiles
135195 );
136196
137- $ path = sprintf ( '%s/%s/%s ' , self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_SUBSCRIBE );
138- $ params = $ this ->createParams ( self ::PROFILES , $ profiles );
197+ $ path = sprintf ('%s/%s/%s ' , self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_SUBSCRIBE );
198+ $ params = $ this ->createParams (self ::PROFILES , $ profiles );
139199
140- return $ this ->v2Request ( $ path , $ params , self ::HTTP_POST );
200+ return $ this ->v2Request ($ path , $ params , self ::HTTP_POST );
141201 }
142202
143203 /**
@@ -178,7 +238,9 @@ public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers
178238
179239 /**
180240 * Unsubscribe and remove profiles from a list.
181- * @link https://www.klaviyo.com/docs/api/v2/lists#delete-subscribe
241+ *
242+ * @deprecated 2.2.6
243+ * @see deleteSubscribersFromList
182244 *
183245 * @param string $listId
184246 * 6 digit unique identifier of the list
@@ -189,6 +251,23 @@ public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers
189251 * @return bool|mixed
190252 */
191253 public function unsubscribeMembersFromList ( $ listId , $ emails )
254+ {
255+ return $ this ->deleteSubscribersFromList ($ listId , $ emails );
256+ }
257+
258+ /**
259+ * Unsubscribe and remove profiles from a list.
260+ * @link https://www.klaviyo.com/docs/api/v2/lists#delete-subscribe
261+ *
262+ * @param string $listId
263+ * 6 digit unique identifier of the list
264+ *
265+ * @param array $emails
266+ * The emails corresponding to the profiles that you would like to check.
267+ *
268+ * @return bool|mixed
269+ */
270+ public function deleteSubscribersFromList ($ listId , $ emails )
192271 {
193272 $ params = $ this ->createRequestJson (
194273 $ this ->filterParams (
@@ -198,9 +277,9 @@ public function unsubscribeMembersFromList( $listId, $emails )
198277 )
199278 );
200279
201- $ path = sprintf ('%s/%s/%s ' , self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_SUBSCRIBE );
280+ $ path = sprintf ('%s/%s/%s ' , self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_SUBSCRIBE );
202281
203- return $ this ->v2Request ( $ path , $ params , self ::HTTP_DELETE );
282+ return $ this ->v2Request ($ path , $ params , self ::HTTP_DELETE );
204283 }
205284
206285 /**
@@ -302,7 +381,9 @@ public function removeMembersFromList( $listId, $emails )
302381 /**
303382 * Get all of the emails and phone numbers that have been excluded from a list along with the exclusion reasons and exclusion time.
304383 * This endpoint uses batching to return the records, so for a large list multiple calls will need to be made to get all of the records.
305- * @link https://www.klaviyo.com/docs/api/v2/lists#get-exclusions-all
384+ *
385+ * @deprecated 2.2.6
386+ * @see getListExclusions
306387 *
307388 * @param $listId
308389 * 6 digit unique identifier of the list
@@ -313,6 +394,24 @@ public function removeMembersFromList( $listId, $emails )
313394 * @return bool|mixed
314395 */
315396 public function getAllExclusionsOnList ( $ listId , $ marker = null )
397+ {
398+ return $ this ->getListExclusions ($ listId , $ marker );
399+ }
400+
401+ /**
402+ * Get all of the emails and phone numbers that have been excluded from a list along with the exclusion reasons and exclusion time.
403+ * This endpoint uses batching to return the records, so for a large list multiple calls will need to be made to get all of the records.
404+ * @link https://www.klaviyo.com/docs/api/v2/lists#get-exclusions-all
405+ *
406+ * @param $listId
407+ * 6 digit unique identifier of the list
408+ *
409+ * @param int $marker
410+ * A marker value returned by a previous GET call. Use this to grab the next batch of records.
411+ *
412+ * @return bool|mixed
413+ */
414+ public function getListExclusions ($ listId , $ marker = null )
316415 {
317416 $ params = $ this ->createRequestBody (
318417 $ this ->filterParams (
@@ -322,15 +421,17 @@ public function getAllExclusionsOnList( $listId, $marker = null )
322421 )
323422 );
324423
325- $ path = sprintf ( '%s/%s/%s/%s ' ,self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_EXCLUSIONS , ' all ' );
424+ $ path = sprintf ('%s/%s/%s/%s ' ,self ::ENDPOINT_LIST , $ listId , self ::ENDPOINT_EXCLUSIONS , self :: ENDPOINT_ALL );
326425
327- return $ this ->v2Request ( $ path , $ params );
426+ return $ this ->v2Request ($ path , $ params );
328427 }
329428
330429 /**
331430 * Get all of the emails, phone numbers, and push tokens for profiles in a given list or segment.
332431 * This endpoint uses batching to return the records, so for a large list or segment multiple calls will need to be made to get all of the records.
333- * @link https://www.klaviyo.com/docs/api/v2/lists#get-members-all
432+ *
433+ * @deprecated 2.2.6
434+ * @see getAllMembers
334435 *
335436 * @param $groupId
336437 * 6 digit unique identifier of List/Segment to get member information about
@@ -341,6 +442,24 @@ public function getAllExclusionsOnList( $listId, $marker = null )
341442 * @return bool|mixed
342443 */
343444 public function getGroupMemberIdentifiers ( $ groupId , $ marker = null )
445+ {
446+ return $ this ->getAllMembers ($ groupId , $ marker );
447+ }
448+
449+ /**
450+ * Get all of the emails, phone numbers, and push tokens for profiles in a given list or segment.
451+ * This endpoint uses batching to return the records, so for a large list or segment multiple calls will need to be made to get all of the records.
452+ * @link https://www.klaviyo.com/docs/api/v2/lists#get-members-all
453+ *
454+ * @param $groupId
455+ * 6 digit unique identifier of List/Segment to get member information about
456+ *
457+ * @param int $marker
458+ * A marker value returned by a previous GET call. Use this to grab the next batch of records.
459+ *
460+ * @return bool|mixed
461+ */
462+ public function getAllMembers ($ groupId , $ marker = null )
344463 {
345464 $ params = $ this ->createRequestBody (
346465 $ this ->filterParams (
@@ -350,7 +469,7 @@ public function getGroupMemberIdentifiers( $groupId, $marker = null )
350469 )
351470 );
352471
353- $ path = sprintf ( '%s/%s/%s/%s ' ,self ::ENDPOINT_GROUP , $ groupId , self ::ENDPOINT_MEMBERS , ' all ' );
354- return $ this ->v2Request ( $ path , $ params );
472+ $ path = sprintf ('%s/%s/%s/%s ' ,self ::ENDPOINT_GROUP , $ groupId , self ::ENDPOINT_MEMBERS , self :: ENDPOINT_ALL );
473+ return $ this ->v2Request ($ path , $ params );
355474 }
356475}
0 commit comments