File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 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
2424}
2525
2626//get session key
27-
2827if ($ response ->getBody ()) {
2928
3029 $ obj = json_decode ($ response ->getBody (), true );
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 ' => [
4646if ($ listInfo ->getBody ()) {
4747
4848 $ listInfoResponse = json_decode ($ listInfo ->getBody (), true );
49+
4950 echo 'List Info: <br><br> ' ;
5051
5152 foreach ($ listInfoResponse as $ key => $ value ) {
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 ' => [
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+ 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 ();
You can’t perform that action at this time.
0 commit comments