Skip to content

Commit a4efbb4

Browse files
committed
Rest Api Client for list and list subcsribers
Signed-off-by: Xheni Myrtaj <myrtajxheni@gmail.com>
0 parents  commit a4efbb4

File tree

121 files changed

+19399
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+19399
-0
lines changed

RESTAPIphpListClient.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* A very simple example of Rest Api client of phpList
4+
* @author Xheni Myrtaj
5+
**/
6+
7+
require __DIR__ . '/vendor/autoload.php';
8+
9+
$client = new \GuzzleHttp\Client();
10+
11+
//Please replace the following values with yours.
12+
$loginname = 'admin';
13+
$password = 'admin1234';
14+
$base_uri = 'http://10.211.55.4:1994/app.php/api/v2';
15+
16+
try {
17+
$response = $client->request('POST', $base_uri.'/sessions', [
18+
'form_params' => [
19+
'login_name' => $loginname,
20+
'password' => $password,
21+
],
22+
]);
23+
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
24+
}
25+
26+
//get session key
27+
if ($response->getBody()) {
28+
$obj = json_decode($response->getBody(), true);
29+
$key = $obj['key'];
30+
echo 'Session key is: ' . $key.'<br><br>';
31+
}
32+
33+
34+
$credentials = base64_encode($loginname . ':' . $key);
35+
36+
$listInfo = $client->get($base_uri.'/lists/1',
37+
[
38+
'headers' => [
39+
'Authorization' => 'Basic ' . $credentials,
40+
'Content-Type' => 'application/json',
41+
],
42+
]);
43+
44+
if ($listInfo->getBody()) {
45+
$listInfoResponse = json_decode($listInfo->getBody(), true);
46+
echo 'List Info: <br><br>';
47+
48+
foreach ($listInfoResponse as $key => $value) {
49+
50+
echo "$key : $value<br>";
51+
}
52+
echo '<br>';
53+
}
54+
55+
$members = $client->get($base_uri.'/lists/1/members',
56+
[
57+
'headers' => [
58+
'Authorization' => 'Basic ' . $credentials,
59+
'Content-Type' => 'application/json',
60+
],
61+
]);
62+
63+
if ($members->getBody()) {
64+
$membersResponse = json_decode($members->getBody(), true);
65+
66+
echo 'Subcsribers data of '.$listInfoResponse['name'].':<br><br>';
67+
68+
foreach ($membersResponse as $k => $val) {
69+
foreach ($val as $key => $value) {
70+
echo "$key : $value<br>";
71+
}
72+
echo '<br>';
73+
}
74+
}
75+
76+
77+

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"guzzlehttp/guzzle": "^6.3"
4+
}
5+
}

vendor/autoload.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer/autoload_real.php';
6+
7+
return ComposerAutoloaderInitbc32eccc823235d189a614a3499e700d::getLoader();

0 commit comments

Comments
 (0)