OK, I misread the release docs referenced in my original question.
I have successfully CURL’d a login. Now the issue is when I try to add a subscriber. Below is my code for the two separate CURL requests.
$url = "https://www.example.com/maillist/api/v2/sessions";
$login = "admin"; // phplist admin Login
$pass = "password"; // phplist admin password
$login_data = array();
$login_data["login_name"] = $login;
$login_data["password"] = $pass;
$post_params = http_build_query($login_data);
$data_string = json_encode($login_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
)
);
$result = curl_exec($ch);
/* response (200)
{"expiry":"2019-04-27T01:37:24+00:00","key":"83bf2b137fb2a6272e641906c0b21c5a","id":165}
*/
$decoded = json_decode($result, true);
$key = $decoded["key"];
$id = $decoded["id"];
$url = "https://www.example.com/maillist/api/v2/subscribers";
$confirmed = true;
$blacklisted = false;
$html_email = true;
$disabled = false;
$params = array(
'email' => 'mickey@mouse.com',
'confirmed' => $confirmed,
'blacklisted' => $blacklisted,
'html_email' => $html_email,
'disabled' => $disabled,
'key' => $key,
'id' => $id,
);
$data_string = json_encode($params);
//$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Authorization: Basic ' . $key,
)
);
$result = curl_exec($ch);
/* response =
{"code":403,"message":"Forbidden"}
*/
As far as I can tell, I’ve got the correct parameters for the 2nd CURL that is supposed to add the subscriber. But, obviously, I am missing something, as I get a ‘403:forbidden’ response to the 2nd CURL.
Thanks…Rick…