REST API not working with php 8.1+

Hello DuncanC,

I am new and see your name quite a bit as I read through the issues. I am wondering on this issue, if you know how long it will be before they update this?

The specific portion of code is referred to as the JMS Serializer and it is a separate open source project. They have an update of this project which works. I have updated the serializer on my own install and am happily coding away for some Wordpress plugins to use that API. Since updating that code, the API behaves exactly as it should and I am on php 8.2.

For anyone brave or curious, if you search for the root of the JMS Serializer in your install and then search for the project, the project owner gives reasonably clear instructions on how to write a composer file to upgrade that code. Afterwards, do a deep grep for any instance of ReadOnly and replace with ReadOnlyProperty (there are only two instances and they are on the same file).

I may write a blog post with phplist specific instructions for this later this week, if anyone is interested. I have been an on and off user of phplist for a long time, I appreciate all the effort people put into it.

Thanks,

Karl Tatgenhorst

@ktatgenhorst I have moved your post to a new topic as it is not directly related to the original problem.

I don’t quite understand your comments on how to resolve the problem with the JMS Serializer package, but the simplest way is to replace the two occurrences of the ReadOnly class alias with the full class name \JMS\Serializer\Annotation\ReadOnly. This avoids using the php 8.1 keyword directly.

For anyone who needs to use the REST API with php 8.1+, to fix the problem, replace this file with the one attached here which is zipped to allow uploading

base/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php

I don’t know when the phplist REST API package will be updated. Looking at the GitHub repositories, they have not had any changes for two years.

AnnotationDriver.php.zip (2.0 KB)

Duncan,

Thank you - that is a much easier solution. The solution I gave actually uses the rewritten JMS serializer.

To follow up on this I have been trying to track down issues with my use of the REST API.

Not least of which is the confusing documentation which conflates PHPList v3 + v4 and different API versions.

I have a 3.6.14 install downloaded from here and installed on a CentOS Linux. I was using PHP8.1 but saw the note above so moved it down to PHP8.0 for more testing which made no difference.

https://www.phplist.org/download-phplist/

I added the API plugin as per this:

https://resources.phplist.com/plugin/restapi

I can then perform a successful login using this:

https://github.com/michield/phplist-restapi-client

But I cannot obtain any information - eg getLists just returns

“Access denied for user ‘phplist’@‘localhost’ (using password: YES)” }"

subscriberFindByEmail returns false. etc.

I then saw the docs indicating there that the PHPList v4 API was installed. So I thought I would looks at that.

https://github.com/phpList/rest-api
https://www.phplist.org/manual/books/phplist-manual/page/api-and-integrations

base/vendor/phplist shows

core
rest-api

But the curl request as indicated fails

curl --request POST --url http://my-website.com/lists/api/v2/sessions --header 'Content-Type: application/json'--data '{"login_name": "admin","password": "phplist"}'

So I really don’t get what is installed and what I can use etc. I also cannot seem to get any logging running despite reading the docs and enabling various settings.

Forehead is feeling a bit sore right now! Any advice appreciated.

Hmmm. A lot of similarities with this as well.

https://discuss.phplist.org/t/newbie-trying-to-use-the-api/8787

Ahhh. In my instance at least it is a bug.

admin/plugins/restapi/includes/pdo.php

It does not have the DB server port number from the config, and I run Maria 10.5 on 3313.

Added as follows and it suddenly works.

--- pdo.php.old	2024-01-05 18:38:56.724455609 +0100
+++ pdo.php	2024-01-05 18:07:00.221162380 +0100
@@ -15,7 +15,8 @@
         $dbuser = $GLOBALS['database_user'];
         $dbpass = $GLOBALS['database_password'];
         $dbname = $GLOBALS['database_name'];
-        $dbh = new \PDO("mysql:host=$dbhost;dbname=$dbname;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
+        $dbport = $GLOBALS['database_port'];
+        $dbh = new \PDO("mysql:host=$dbhost;dbname=$dbname;port=$dbport;charset=UTF8;", $dbuser, $dbpass, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8';"));
         $dbh->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 
         return $dbh;

Not sure it is worth a patch as this is deprecated.

Next to find out about the PHP v4 version :worried: