Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.

Commit ce2f66b

Browse files
authored
Merge pull request #53 from klaviyo/202104_deprecate_misnamed_methods
Deprecate lists and metrics methods
2 parents 2d277fe + 8f946ae commit ce2f66b

4 files changed

Lines changed: 236 additions & 53 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## CHANGELOG
2-
32
### [Unreleased]
43
- Update - Add people/search endpoint.
54
- Update - Add data-privacy/deletion-request endpoint.
5+
- Deprecate - Rename List API methods: getListDetails, updateListDetails, subscribeMembersToList, unsubscribeMembersFromList, getGroupMemberIdentifiers, getAllExclusionsOnList
6+
- Deprecate - Rename Metric API methods: getMetricTimeline, exportMetricData
67

78
### 2.2.5
89
- Update - Add error details into KlaviyoAPI handleResponse function

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ $client->metrics->getMetrics();
8888
$client->metrics->getMetricsTimeline();
8989

9090
#return a specific metric timeline using its metric ID
91-
$client->metrics->getMetricTimeline( 'METRICID' );
91+
$client->metrics->getMetricTimelineById( 'METRICID' );
9292

9393
#export metric specific values
94-
$client->metrics->exportMetricData( 'METRICID' );
94+
$client->metrics->getMetricExport( 'METRICID' );
9595
```
9696

9797
### You can create, update, read, and delete lists. See here for more information https://www.klaviyo.com/docs/api/v2/lists
@@ -103,22 +103,22 @@ $client->lists->createList( 'List Name' );
103103
$client->lists->getLists();
104104

105105
#Get information about a list
106-
$client->lists->getListDetails( 'ListId' );
106+
$client->lists->getListById( 'ListId' );
107107

108108
#update a lists properties
109-
$client->lists->updateListDetails( 'ListId', 'ListName' );
109+
$client->lists->updateListNameById( 'ListId', 'ListName' );
110110

111111
#Delete a list from account
112112
$client->lists->deleteList( 'ListId' );
113113

114114
#Subscribe or re-subscribe profiles to a list
115-
$client->lists->subscribeMemberstoList( 'ListId', array $arrayOfProfiles );
115+
$client->lists->addSubscribersToList( 'ListId', array $arrayOfProfiles );
116116

117117
#Check if profiles are on a list and not suppressed
118118
$client->lists->checkListSubscriptions( 'ListId', array $emails, array $phoneNumbers, array $pushTokens );
119119

120120
#Unsubscribe and remove profiles from a list
121-
$client->lists->unsubscribeMembersFromList( 'ListId', array $emails );
121+
$client->lists->deleteSubscribersFromList( 'ListId', array $emails );
122122

123123
#Add members to list without affecting consent status
124124
$client->lists->addMembersToList( 'ListId', array $arrayOfProfiles );
@@ -130,10 +130,10 @@ $client->lists->checkListMembership( 'ListId', array $emails, array $phoneNumber
130130
$client->lists->removeMembersFromList( 'ListId', array $emails );
131131

132132
#Get all exclusions on a list
133-
$client->lists->getAllExclusionsOnList( 'ListId' );
133+
$client->lists->getListExclusions( 'ListId' );
134134

135135
#Get all of the emails, phone numbers and push tokens for profiles in a given list or segment
136-
$client->lists->getGroupMemberIdentifiers( 'GroupId' );
136+
$client->lists->getAllMembers( 'GroupId' );
137137
```
138138

139139
### You can fetch profile information given the profile ID, See here for more information https://www.klaviyo.com/docs/api/people

src/Lists.php

Lines changed: 145 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)