From 04cdedc4d5f3a65ecf6b097815c718140013d340 Mon Sep 17 00:00:00 2001 From: Xheni Myrtaj Date: Wed, 27 Mar 2019 21:36:45 +0000 Subject: [PATCH] Add subscriber call and add docs --- RESTAPIphpListClient.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/RESTAPIphpListClient.php b/RESTAPIphpListClient.php index 8e035f8..be90ecb 100644 --- a/RESTAPIphpListClient.php +++ b/RESTAPIphpListClient.php @@ -1,6 +1,6 @@ getBody()) { $obj = json_decode($response->getBody(), true); @@ -35,6 +34,7 @@ //Use session key as password for basic auth $credentials = base64_encode($loginname . ':' . $key); +// Get list info where id=1 $listInfo = $client->get($base_uri . '/lists/1', [ 'headers' => [ @@ -46,6 +46,7 @@ if ($listInfo->getBody()) { $listInfoResponse = json_decode($listInfo->getBody(), true); + echo 'List Info:

'; foreach ($listInfoResponse as $key => $value) { @@ -55,6 +56,7 @@ echo '
'; } +//Get all subscribers where list id=1 $members = $client->get($base_uri . '/lists/1/members', [ 'headers' => [ @@ -76,3 +78,24 @@ echo '
'; } } + +// Add a new subscriber +try { + $subscriberRequest = $client->request('POST', $base_uri . '/subscribers', + [ + 'headers' => [ + 'Authorization' => 'Basic ' . $credentials, + 'Content-Type' => 'application/json', + ], + 'json' => [ + 'email' => 'restapi@example.com', + 'confirmed' => true, + 'blacklisted' => false, + 'html_email' => true, + 'disabled' => false, + ], + ] + ); +} catch (\GuzzleHttp\Exception\GuzzleException $e) { +} +$subscriberRequest->getBody();