Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions RESTAPIphpListClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* A very simple example of Rest Api client of phpList
* A very simple example of REST API client of phpList
* @author Xheni Myrtaj
**/

Expand All @@ -24,7 +24,6 @@
}

//get session key

if ($response->getBody()) {

$obj = json_decode($response->getBody(), true);
Expand All @@ -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' => [
Expand All @@ -46,6 +46,7 @@
if ($listInfo->getBody()) {

$listInfoResponse = json_decode($listInfo->getBody(), true);

echo 'List Info: <br><br>';

foreach ($listInfoResponse as $key => $value) {
Expand All @@ -55,6 +56,7 @@
echo '<br>';
}

//Get all subscribers where list id=1
$members = $client->get($base_uri . '/lists/1/members',
[
'headers' => [
Expand All @@ -76,3 +78,24 @@
echo '<br>';
}
}

// 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();