From 0c8df6c9c5e74d8c01e268fabbb29bc77e8137eb Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Thu, 9 May 2024 10:13:08 +0300 Subject: [PATCH 01/14] Add additional params to listSubscribe --- src/Api/ZohoCampaignsApi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 040498a..546fc13 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -19,16 +19,16 @@ public function __construct( * code: int, * } */ - public function listSubscribe(string $listKey, string $email, array $contactInfo = []): array + public function listSubscribe(string $listKey, string $email, array $contactInfo = [], array $additionalParams = []): array { - $params = [ + $params = array_merge([ 'listkey' => $listKey, 'resfmt' => 'JSON', 'contactinfo' => json_encode(array_merge([ 'Contact Email' => $email, ], $contactInfo)), - ]; - + ], $additionalParams); + return Http::baseUrl($this->endpoint()) ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') ->withHeaders([ From 848f9bf0eeb4a092e5170e423789fda6fb9cabc1 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Thu, 9 May 2024 10:19:02 +0300 Subject: [PATCH 02/14] Add resubscibe method to campains --- src/Campaigns.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Campaigns.php b/src/Campaigns.php index bb62ae9..2aa5192 100755 --- a/src/Campaigns.php +++ b/src/Campaigns.php @@ -51,6 +51,25 @@ public function unsubscribe(string $email, ?string $listName = null): array ]; } + + /** + * @return array{success: bool, message?: string} + */ + public function resubscribe(string $email, ?array $contactInfo = [], string $listName = null): array + { + $listKey = $this->resolveListKey($listName); + + $additionalParams = ['donotmail_resub' => true]; + + $response = $this->zohoApi->listSubscribe($listKey, $email, $contactInfo, $additionalParams); + + return [ + 'success' => Arr::get($response, 'status') === 'success', + 'message' => Arr::get($response, 'message'), + ]; + } + + protected function resolveListKey(?string $listName = null): string { $listName = $listName ?? $this->defaultListName; From 7e25db06d8aa45841935aa08555f6feb7a1f9467 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Fri, 10 May 2024 07:16:09 +0300 Subject: [PATCH 03/14] Added resusbscribe method to campains Facades docs --- src/Facades/Campaigns.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Facades/Campaigns.php b/src/Facades/Campaigns.php index 4641e31..0912903 100644 --- a/src/Facades/Campaigns.php +++ b/src/Facades/Campaigns.php @@ -6,6 +6,7 @@ /** * @method static array|null subscribe(string $email, ?array $contactInfo = [], string $listName = null) + * @method static array|null resubscribe(string $email, ?array $contactInfo = [], string $listName = null) * @method static array|null unsubscribe(string $email, string $listName = null) * * @see \Keepsuit\Campaigns\Campaigns From 26c32095657695812bd6d5f151df0c1021d9d29a Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Mon, 13 May 2024 09:27:41 +0300 Subject: [PATCH 04/14] dump params for listSubscribe --- src/Api/ZohoCampaignsApi.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 546fc13..28c4bd0 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -28,7 +28,9 @@ public function listSubscribe(string $listKey, string $email, array $contactInfo 'Contact Email' => $email, ], $contactInfo)), ], $additionalParams); - + + dump(params); + return Http::baseUrl($this->endpoint()) ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') ->withHeaders([ From f03ab73caf441017f247bd7a79aad6d5d6ac7984 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Mon, 13 May 2024 09:32:53 +0300 Subject: [PATCH 05/14] fix --- src/Api/ZohoCampaignsApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 28c4bd0..162bf3f 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -29,7 +29,7 @@ public function listSubscribe(string $listKey, string $email, array $contactInfo ], $contactInfo)), ], $additionalParams); - dump(params); + dump($params); return Http::baseUrl($this->endpoint()) ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') From 1ef67c105153117a8076186fb7578e52fd0358a2 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Mon, 13 May 2024 09:46:39 +0300 Subject: [PATCH 06/14] fix 2 --- src/Api/ZohoCampaignsApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 162bf3f..1cb5dd1 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -29,7 +29,7 @@ public function listSubscribe(string $listKey, string $email, array $contactInfo ], $contactInfo)), ], $additionalParams); - dump($params); + dump(http_build_query($params)); return Http::baseUrl($this->endpoint()) ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') From 82c933364ab82388bebe84ca5a6c593400c4aedb Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Mon, 13 May 2024 09:49:22 +0300 Subject: [PATCH 07/14] use textual representation of true to see if it works --- src/Campaigns.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Campaigns.php b/src/Campaigns.php index 2aa5192..c962a80 100755 --- a/src/Campaigns.php +++ b/src/Campaigns.php @@ -59,7 +59,7 @@ public function resubscribe(string $email, ?array $contactInfo = [], string $lis { $listKey = $this->resolveListKey($listName); - $additionalParams = ['donotmail_resub' => true]; + $additionalParams = ['donotmail_resub' => 'true']; $response = $this->zohoApi->listSubscribe($listKey, $email, $contactInfo, $additionalParams); From d0d8d43ac343a90796b10c7adf092bc00f586fcb Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Mon, 13 May 2024 09:58:06 +0300 Subject: [PATCH 08/14] cleanup --- src/Api/ZohoCampaignsApi.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 1cb5dd1..0499ff6 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -28,8 +28,6 @@ public function listSubscribe(string $listKey, string $email, array $contactInfo 'Contact Email' => $email, ], $contactInfo)), ], $additionalParams); - - dump(http_build_query($params)); return Http::baseUrl($this->endpoint()) ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') From 79b1e80fbd12f1f8429f1a21374f9d78ec1d7073 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Tue, 14 May 2024 10:22:47 +0300 Subject: [PATCH 09/14] add methods to get the list of subscribers from the API --- src/Api/ZohoCampaignsApi.php | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 0499ff6..6996043 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -64,6 +64,63 @@ public function listUnsubscribe(string $listKey, string $email): array ->json(); } + /** + * Retrieves the list of subscribers for a given list key with various options. + * + * @param string $listKey The list key. + * @param array $options An array of options for the request. Possible keys include: + * - 'sort': The sort order of the results. Possible values are 'asc' for ascending order and 'desc' for descending order. + * - 'fromindex': The starting index for the results. This is a number. + * - 'range': The range of results to retrieve. This is a number. + * - 'status': The status of the subscribers to retrieve. Possible values are 'active', 'recent', 'mostrecent', 'unsub', and 'bounce'. + * @return array The list of subscribers. + */ + public function getListSubscribers(string $listKey, array $options = []): array + { + $params = array_merge([ + 'listkey' => $listKey, + 'resfmt' => 'JSON', + ], $options); + + $response = Http::baseUrl($this->endpoint()) + ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') + ->withHeaders([ + 'Content-Type' => 'application/x-www-form-urlencoded', + ]) + ->get(sprintf('/json/getlistsubscribers?%s', http_build_query($params))) + ->json(); + + return $response['list_of_details'] ?? []; + } + + + /** + * Retrieves the count of subscribers for a given list key and status. + * + * @param string $listKey The list key. + * @param string $status The status of the subscribers to count. Possible values are 'active', 'unsub', 'bounce', and 'spam'. + * @return int The count of subscribers. + */ + public function getListSubscribersCount(string $listKey, string $status='active'): int + { + $params = [ + 'listkey' => $listKey, + 'resfmt' => 'JSON', + 'status' => $status, + ]; + + $response = Http::baseUrl($this->endpoint()) + ->withToken($this->accessToken->get(), 'Zoho-oauthtoken') + ->withHeaders([ + 'Content-Type' => 'application/x-www-form-urlencoded', + ]) + ->get(sprintf('/json/listsubscriberscount?%s', http_build_query($params))) + ->json(); + + return $response['no_of_contacts'] ?? 0; + } + + protected function endpoint(): string { return sprintf('https://campaigns.%s/api/v1.1', $this->region->domain()); From 2bde0ca168c8135df6f1a45b2af85f55a2ce7735 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Wed, 15 May 2024 08:24:39 +0300 Subject: [PATCH 10/14] add getSubscribers function to Campaigns.php --- src/Campaigns.php | 18 ++++++++++++++++++ src/Facades/Campaigns.php | 1 + 2 files changed, 19 insertions(+) diff --git a/src/Campaigns.php b/src/Campaigns.php index c962a80..f6bd11e 100755 --- a/src/Campaigns.php +++ b/src/Campaigns.php @@ -69,6 +69,24 @@ public function resubscribe(string $email, ?array $contactInfo = [], string $lis ]; } + /** + * Retrieves subscribers for a given list name. + * + * @param string|null $listName The name of the list. If null, the default list name will be used. + * @param array $options An array of options for the request. Possible keys include: + * - 'sort': The sort order of the results. Possible values are 'asc' for ascending order and 'desc' for descending order. + * - 'fromindex': The starting index for the results. This is a number. + * - 'range': The range of results to retrieve. This is a number. + * - 'status': The status of the subscribers to retrieve. Possible values are 'active', 'recent', 'mostrecent', 'unsub', and 'bounce'. + * @return array The list of subscribers. + */ + public function getSubscribers(?string $listName = null, array $options = []): array + { + $listKey = $this->resolveListKey($listName); + + return $this->zohoApi->getListSubscribers($listKey, $options); + } + protected function resolveListKey(?string $listName = null): string { diff --git a/src/Facades/Campaigns.php b/src/Facades/Campaigns.php index 0912903..020b4fc 100644 --- a/src/Facades/Campaigns.php +++ b/src/Facades/Campaigns.php @@ -8,6 +8,7 @@ * @method static array|null subscribe(string $email, ?array $contactInfo = [], string $listName = null) * @method static array|null resubscribe(string $email, ?array $contactInfo = [], string $listName = null) * @method static array|null unsubscribe(string $email, string $listName = null) + * @method static array|null getSubscribers(?string $listName = null, array $options = []) * * @see \Keepsuit\Campaigns\Campaigns */ From 0d90f22fd79cca20b04c366789e5230b4584c1df Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Wed, 15 May 2024 08:35:52 +0300 Subject: [PATCH 11/14] add countSubscribers method --- src/Campaigns.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Campaigns.php b/src/Campaigns.php index f6bd11e..572c451 100755 --- a/src/Campaigns.php +++ b/src/Campaigns.php @@ -88,6 +88,21 @@ public function getSubscribers(?string $listName = null, array $options = []): a } + /** + * Retrieves the count of subscribers for a given list name and status. + * + * @param string|null $listName The name of the list. If null, the default list name will be used. + * @param string $status The status of the subscribers to count. Possible values are 'active', 'unsub', 'bounce', and 'spam'. + * @return int The count of subscribers. + */ + public function countSubscribers(?string $listName = null, string $status = 'active'): int + { + $listKey = $this->resolveListKey($listName); + + return $this->zohoApi->getListSubscribersCount($listKey, $status); + } + + protected function resolveListKey(?string $listName = null): string { $listName = $listName ?? $this->defaultListName; From bef21c6cee2460162d5d977895e11a89b9a12971 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Wed, 15 May 2024 08:48:45 +0300 Subject: [PATCH 12/14] fix getListSubscribers and getListSubscribersCount request url --- src/Api/ZohoCampaignsApi.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 6996043..7caed8a 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -87,8 +87,10 @@ public function getListSubscribers(string $listKey, array $options = []): array ->withHeaders([ 'Content-Type' => 'application/x-www-form-urlencoded', ]) - ->get(sprintf('/json/getlistsubscribers?%s', http_build_query($params))) + ->get(sprintf('/getlistsubscribers?%s', http_build_query($params))) ->json(); + + dump($response); return $response['list_of_details'] ?? []; } @@ -114,9 +116,10 @@ public function getListSubscribersCount(string $listKey, string $status='active' ->withHeaders([ 'Content-Type' => 'application/x-www-form-urlencoded', ]) - ->get(sprintf('/json/listsubscriberscount?%s', http_build_query($params))) + ->get(sprintf('/listsubscriberscount?%s', http_build_query($params))) ->json(); - + + dump($response); return $response['no_of_contacts'] ?? 0; } From c86e73685d8b1f1c7b905259fae0f28d29e7d3ab Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Wed, 15 May 2024 08:57:32 +0300 Subject: [PATCH 13/14] add countSubscribers do campains facade doc --- src/Facades/Campaigns.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Facades/Campaigns.php b/src/Facades/Campaigns.php index 020b4fc..e996bb0 100644 --- a/src/Facades/Campaigns.php +++ b/src/Facades/Campaigns.php @@ -9,6 +9,7 @@ * @method static array|null resubscribe(string $email, ?array $contactInfo = [], string $listName = null) * @method static array|null unsubscribe(string $email, string $listName = null) * @method static array|null getSubscribers(?string $listName = null, array $options = []) + * @method static array|null countSubscribers(?string $listName = null, string $status = 'active') * * @see \Keepsuit\Campaigns\Campaigns */ From 0b2f7c302a42aca80bc03777dec7671852bfb444 Mon Sep 17 00:00:00 2001 From: Andy <75330721+andreibaca@users.noreply.github.com> Date: Fri, 17 May 2024 16:28:24 +0300 Subject: [PATCH 14/14] cleanup --- src/Api/ZohoCampaignsApi.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Api/ZohoCampaignsApi.php b/src/Api/ZohoCampaignsApi.php index 7caed8a..f130a3c 100644 --- a/src/Api/ZohoCampaignsApi.php +++ b/src/Api/ZohoCampaignsApi.php @@ -89,8 +89,6 @@ public function getListSubscribers(string $listKey, array $options = []): array ]) ->get(sprintf('/getlistsubscribers?%s', http_build_query($params))) ->json(); - - dump($response); return $response['list_of_details'] ?? []; } @@ -119,7 +117,6 @@ public function getListSubscribersCount(string $listKey, string $status='active' ->get(sprintf('/listsubscriberscount?%s', http_build_query($params))) ->json(); - dump($response); return $response['no_of_contacts'] ?? 0; }