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

Commit

Permalink
Merge pull request #53 from klaviyo/202104_deprecate_misnamed_methods
Browse files Browse the repository at this point in the history
Deprecate lists and metrics methods
  • Loading branch information
smoucka authored Apr 14, 2021
2 parents 2d277fe + 8f946ae commit ce2f66b
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 53 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## CHANGELOG

### [Unreleased]
- Update - Add people/search endpoint.
- Update - Add data-privacy/deletion-request endpoint.
- Deprecate - Rename List API methods: getListDetails, updateListDetails, subscribeMembersToList, unsubscribeMembersFromList, getGroupMemberIdentifiers, getAllExclusionsOnList
- Deprecate - Rename Metric API methods: getMetricTimeline, exportMetricData

### 2.2.5
- Update - Add error details into KlaviyoAPI handleResponse function
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ $client->metrics->getMetrics();
$client->metrics->getMetricsTimeline();

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

#export metric specific values
$client->metrics->exportMetricData( 'METRICID' );
$client->metrics->getMetricExport( 'METRICID' );
```

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

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

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

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

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

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

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

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

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

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

### You can fetch profile information given the profile ID, See here for more information https://www.klaviyo.com/docs/api/people
Expand Down
171 changes: 145 additions & 26 deletions src/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Lists extends KlaviyoAPI
/**
* List endpoint constants
*/
const ENDPOINT_ALL = 'all';
const ENDPOINT_EXCLUSIONS = 'exclusions';
const ENDPOINT_GROUP = 'group';
const ENDPOINT_LIST = 'list';
Expand Down Expand Up @@ -57,22 +58,40 @@ public function getLists() {

/**
* Get information about a list
* @link https://www.klaviyo.com/docs/api/v2/lists#get-list
*
* @param $listId
* @deprecated 2.2.6
* @see getListById
*
* @param string $listId
* 6 digit unique identifier of the list
*
* @return bool|mixed
*/
public function getListDetails( $listId )
{
$path = sprintf( '%s/%s', self::ENDPOINT_LIST, $listId );
return $this->v2Request( $path );
return $this->getListById($listId);
}

/**
* Get information about a list.
* @link https://www.klaviyo.com/docs/api/v2/lists#get-list
*
* @param string $listId
* 6 digit unique identifier of the list
*
* @return bool|mixed
*/
public function getListById($listId)
{
$path = sprintf('%s/%s', self::ENDPOINT_LIST, $listId);
return $this->v2Request($path);
}

/**
* Update a list's properties
* @link https://www.klaviyo.com/docs/api/v2/lists#put-list
*
* @deprecated 2.2.6
* @see updateListNameById
*
* @param $listId
* 6 digit unique identifier of the list
Expand All @@ -84,13 +103,30 @@ public function getListDetails( $listId )
*/
public function updateListDetails( $listId, $list_name )
{
$params = $this->createRequestBody( array(
self::LIST_NAME => $list_name
) );
return $this->updateListNameById($listId, $list_name);
}

$path = sprintf( '%s/%s', self::ENDPOINT_LIST, $listId );
/**
* Update a list's name.
* @link https://www.klaviyo.com/docs/api/v2/lists#put-list
*
* @param string $listId
* 6 digit unique identifier of the list
*
* @param string $listName
* String to update list name to
*
* @return bool|mixed
*/
public function updateListNameById($listId, $listName)
{
$params = $this->createRequestBody(
array(self::LIST_NAME => $listName)
);

$path = sprintf('%s/%s', self::ENDPOINT_LIST, $listId);

return $this->v2Request( $path, $params, self::HTTP_PUT );
return $this->v2Request($path, $params, self::HTTP_PUT);
}

/**
Expand All @@ -110,7 +146,9 @@ public function deleteList( $listId )

/**
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#post-subscribe
*
* @deprecated 2.2.6
* @see addSubscribersToList
*
* @param $listId
* 6 digit unique identifier of the list
Expand All @@ -126,18 +164,40 @@ public function deleteList( $listId )
*/
public function subscribeMembersToList( $listId, $profiles )
{
$this->checkProfile( $profiles );
return $this->addSubscribersToList($listId, $profiles);
}

/**
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#post-subscribe
*
* @param $listId
* 6 digit unique identifier of the list
*
* @param array $profiles
* The profiles that you would like to subscribe. Each object in the list must have either an email or phone number key.
* 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.
* $consent is a Klaviyo special property and only accepts the following values: "email", "web", "sms", "directmail", "mobile".
* 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.
*
* @return bool|mixed
* @throws Exception\KlaviyoException
*/
public function addSubscribersToList($listId, $profiles)
{
$this->checkProfile($profiles);

$profiles = array_map(
function( $profile ) {
function($profile) {
return $profile->toArray();
}, $profiles
},
$profiles
);

$path = sprintf( '%s/%s/%s', self::ENDPOINT_LIST, $listId, self::ENDPOINT_SUBSCRIBE );
$params = $this->createParams( self::PROFILES, $profiles );
$path = sprintf('%s/%s/%s', self::ENDPOINT_LIST, $listId, self::ENDPOINT_SUBSCRIBE);
$params = $this->createParams(self::PROFILES, $profiles);

return $this->v2Request( $path, $params, self::HTTP_POST );
return $this->v2Request($path, $params, self::HTTP_POST);
}

/**
Expand Down Expand Up @@ -178,7 +238,9 @@ public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers

/**
* Unsubscribe and remove profiles from a list.
* @link https://www.klaviyo.com/docs/api/v2/lists#delete-subscribe
*
* @deprecated 2.2.6
* @see deleteSubscribersFromList
*
* @param string $listId
* 6 digit unique identifier of the list
Expand All @@ -189,6 +251,23 @@ public function checkListSubscriptions ($listId, $emails = null, $phoneNumbers
* @return bool|mixed
*/
public function unsubscribeMembersFromList( $listId, $emails )
{
return $this->deleteSubscribersFromList($listId, $emails);
}

/**
* Unsubscribe and remove profiles from a list.
* @link https://www.klaviyo.com/docs/api/v2/lists#delete-subscribe
*
* @param string $listId
* 6 digit unique identifier of the list
*
* @param array $emails
* The emails corresponding to the profiles that you would like to check.
*
* @return bool|mixed
*/
public function deleteSubscribersFromList($listId, $emails)
{
$params = $this->createRequestJson(
$this->filterParams(
Expand All @@ -198,9 +277,9 @@ public function unsubscribeMembersFromList( $listId, $emails )
)
);

$path = sprintf('%s/%s/%s', self::ENDPOINT_LIST, $listId, self::ENDPOINT_SUBSCRIBE );
$path = sprintf('%s/%s/%s', self::ENDPOINT_LIST, $listId, self::ENDPOINT_SUBSCRIBE);

return $this->v2Request( $path, $params, self::HTTP_DELETE );
return $this->v2Request($path, $params, self::HTTP_DELETE);
}

/**
Expand Down Expand Up @@ -302,7 +381,9 @@ public function removeMembersFromList( $listId, $emails )
/**
* Get all of the emails and phone numbers that have been excluded from a list along with the exclusion reasons and exclusion time.
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#get-exclusions-all
*
* @deprecated 2.2.6
* @see getListExclusions
*
* @param $listId
* 6 digit unique identifier of the list
Expand All @@ -313,6 +394,24 @@ public function removeMembersFromList( $listId, $emails )
* @return bool|mixed
*/
public function getAllExclusionsOnList( $listId, $marker = null )
{
return $this->getListExclusions($listId, $marker);
}

/**
* Get all of the emails and phone numbers that have been excluded from a list along with the exclusion reasons and exclusion time.
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#get-exclusions-all
*
* @param $listId
* 6 digit unique identifier of the list
*
* @param int $marker
* A marker value returned by a previous GET call. Use this to grab the next batch of records.
*
* @return bool|mixed
*/
public function getListExclusions($listId, $marker = null)
{
$params = $this->createRequestBody(
$this->filterParams(
Expand All @@ -322,15 +421,17 @@ public function getAllExclusionsOnList( $listId, $marker = null )
)
);

$path = sprintf( '%s/%s/%s/%s',self::ENDPOINT_LIST, $listId, self::ENDPOINT_EXCLUSIONS, 'all' );
$path = sprintf('%s/%s/%s/%s',self::ENDPOINT_LIST, $listId, self::ENDPOINT_EXCLUSIONS, self::ENDPOINT_ALL);

return $this->v2Request( $path, $params );
return $this->v2Request($path, $params);
}

/**
* Get all of the emails, phone numbers, and push tokens for profiles in a given list or segment.
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#get-members-all
*
* @deprecated 2.2.6
* @see getAllMembers
*
* @param $groupId
* 6 digit unique identifier of List/Segment to get member information about
Expand All @@ -341,6 +442,24 @@ public function getAllExclusionsOnList( $listId, $marker = null )
* @return bool|mixed
*/
public function getGroupMemberIdentifiers( $groupId, $marker = null )
{
return $this->getAllMembers($groupId, $marker);
}

/**
* Get all of the emails, phone numbers, and push tokens for profiles in a given list or segment.
* 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.
* @link https://www.klaviyo.com/docs/api/v2/lists#get-members-all
*
* @param $groupId
* 6 digit unique identifier of List/Segment to get member information about
*
* @param int $marker
* A marker value returned by a previous GET call. Use this to grab the next batch of records.
*
* @return bool|mixed
*/
public function getAllMembers($groupId, $marker = null)
{
$params = $this->createRequestBody(
$this->filterParams(
Expand All @@ -350,7 +469,7 @@ public function getGroupMemberIdentifiers( $groupId, $marker = null )
)
);

$path = sprintf( '%s/%s/%s/%s',self::ENDPOINT_GROUP, $groupId, self::ENDPOINT_MEMBERS, 'all' );
return $this->v2Request( $path, $params );
$path = sprintf('%s/%s/%s/%s',self::ENDPOINT_GROUP, $groupId, self::ENDPOINT_MEMBERS, self::ENDPOINT_ALL);
return $this->v2Request($path, $params);
}
}
Loading

0 comments on commit ce2f66b

Please sign in to comment.