Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
chavesj authored Dec 13, 2023
2 parents 4900686 + 501ba91 commit 7541dda
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fabric.properties

.idea/*

!.idea/codeStyles
#!.idea/codeStyles
!.idea/runConfigurations

### PHPUnit ###
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Changed
- Changed system.xml sort to stop becoming default instead of core options

#### Fixed
- Updated getKlaviyoLists() exception handling to properly print error message.
- Paginate to get all lists for account.

### [4.1.0] - 2023-09-29

#### Added
Expand Down
4 changes: 2 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public function getKlaviyoLists()
'lists' => $lists
];
} catch (\Exception $e) {
$this->_klaviyoLogger->log(sprintf('Unable to get list: %s', $e["detail"]));
$this->_klaviyoLogger->log(sprintf('Unable to get list: %s', $e->getMessage()));
return [
'success' => false,
'reason' => $e["detail"]
'reason' => $e->getMessage()
];
}
}
Expand Down
16 changes: 14 additions & 2 deletions KlaviyoV3Sdk/KlaviyoV3Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class KlaviyoV3Api
*/
const CUSTOMER_PROPERTIES_MAP = ['$email' => 'email', 'firstname' => 'first_name', 'lastname' => 'last_name', '$exchange_id' => '_kx'];
const DATA_KEY_PAYLOAD = 'data';
const LINKS_KEY_PAYLOAD = 'links';
const NEXT_KEY_PAYLOAD = 'next';
const TYPE_KEY_PAYLOAD = 'type';
const ATTRIBUTE_KEY_PAYLOAD = 'attributes';
const PROPERTIES_KEY_PAYLOAD = 'properties';
Expand Down Expand Up @@ -138,9 +140,19 @@ public function getHeaders()
*/
public function getLists()
{
$response_body = $this->requestV3('api/lists/', self::HTTP_GET);
$response = $this->requestV3('api/lists/', self::HTTP_GET);
$lists = $response[self::DATA_KEY_PAYLOAD];

return $response_body[self::DATA_KEY_PAYLOAD];
$next = $response[self::LINKS_KEY_PAYLOAD][self::NEXT_KEY_PAYLOAD];
while ($next) {
$next_qs = explode("?", $next)[1];
$response = $this->requestV3("api/lists/?$next_qs", self::HTTP_GET);
array_push($lists, ...$response[self::DATA_KEY_PAYLOAD]);

$next = $response[self::LINKS_KEY_PAYLOAD][self::NEXT_KEY_PAYLOAD];
}

return $lists;
}

/**
Expand Down

0 comments on commit 7541dda

Please sign in to comment.