Skip to content

Commit 2d676c8

Browse files
authored
Merge pull request #1 from phpList/add-subscriber-call
Add subscriber call and add docs
2 parents e2c643f + 04cdedc commit 2d676c8

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

RESTAPIphpListClient.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* A very simple example of Rest Api client of phpList
3+
* A very simple example of REST API client of phpList
44
* @author Xheni Myrtaj
55
**/
66

@@ -24,7 +24,6 @@
2424
}
2525

2626
//get session key
27-
2827
if ($response->getBody()) {
2928

3029
$obj = json_decode($response->getBody(), true);
@@ -35,6 +34,7 @@
3534
//Use session key as password for basic auth
3635
$credentials = base64_encode($loginname . ':' . $key);
3736

37+
// Get list info where id=1
3838
$listInfo = $client->get($base_uri . '/lists/1',
3939
[
4040
'headers' => [
@@ -46,6 +46,7 @@
4646
if ($listInfo->getBody()) {
4747

4848
$listInfoResponse = json_decode($listInfo->getBody(), true);
49+
4950
echo 'List Info: <br><br>';
5051

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

59+
//Get all subscribers where list id=1
5860
$members = $client->get($base_uri . '/lists/1/members',
5961
[
6062
'headers' => [
@@ -76,3 +78,24 @@
7678
echo '<br>';
7779
}
7880
}
81+
82+
// Add a new subscriber
83+
try {
84+
$subscriberRequest = $client->request('POST', $base_uri . '/subscribers',
85+
[
86+
'headers' => [
87+
'Authorization' => 'Basic ' . $credentials,
88+
'Content-Type' => 'application/json',
89+
],
90+
'json' => [
91+
'email' => '[email protected]',
92+
'confirmed' => true,
93+
'blacklisted' => false,
94+
'html_email' => true,
95+
'disabled' => false,
96+
],
97+
]
98+
);
99+
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
100+
}
101+
$subscriberRequest->getBody();

0 commit comments

Comments
 (0)