Newbie trying to use the API

Hello, I’m trying to move away from mailchimp and having some trouble getting the api to work.

I am trying the test curl command from the documentation (with the space inserted before --data), but there is no response at all, not a 500 or 404.

curl --request POST --url https://mywebsite.com/phpList/api/v2/sessions --header ‘Content-Type: application/json’ --data ‘{“login_name”: “admin”,“password”: “password”}’

If I enter an incorrect path I get a 404 response. The admin page works fine.

I put a new Ubuntu server installation on a laptop locally and installed phpList on it, with the same result, so I assume I must be doing something wrong. I have been through the forum, checked that .htaccess is working and looks correct. My bash history got cleared so I have trouble remembering exactly what else I tried.

I’m unsure how to debug from here, any suggestions would be welcome!

@brorme The API was broken in an earlier release of phplist and hasn’t yet been fixed see API broken in release 3.6.10 · Issue #906 · phpList/phplist3 · GitHub

The RESTAPI plugin might do what you want, see https://resources.phplist.com/plugin/restapi

Thank you, I wiped the laptop and tried again with php 7.4 and phpList 3.6.9, with the same result.

This time, curl with

mywebsite.com is available for purchase - Sedo.com

returns a 404, while

mywebsite.com is available for purchase - Sedo.com

returns nothing, which if I understand correctly just means the .htaccess file isn’t enabled.

I will give the plugin a try, but I’m worried that I cannot get the built-in api to work even now.

This should be sessions

and you have made the change to file base/config/config_modules.yml

Apologies, I missed the last s when pasting into the forum. The result is the same with missing s.

Here is the full command I’m pasting just in case:

curl --request POST --url lappyserv.lan/lists/api.php/v2/sessions --header ‘Content-Type: application/json’ --data ‘{“login_name”: “admin”,“password”: “temp_password”}’

I did make the change in the config_modules.yml file yes.

@brorme The command needs to be /api/ not /api.php/, which is what you had in your original post.

I thought api.php should work also, might be wrong there.

I added AllowOverride All to apache2.conf and enabled rewriting with a2enmod rewrite, so now both the /api/ and /api.php/ urls return blank.

@brorme Do the apache log or php error log show anything?

Your command works for me, so the format is correct

duncan@duncan-OptiPlex-990 ~ $ curl --request POST --url strontian/lists/api/v2/sessions --header 'Content-Type: application/json' --data '{"login_name": "admin","password": "password"}'
{"expiry":"2023-03-23T13:09:13+00:00","key":"37cdff3ed9307efdfca0347a2bb2126f","id":405}

Try adding --verbose to the command

It’s getting somewhere! There were some errors in var/log/apache2/error.log caused by permissions on the lists/base/var/cache and lists/base/var/logs folders. I also had to declare $databse_port and $table_prefix in lists/config.php.

Now it returns a 500 server error, but nothing gets logged to /var/log/apache2/error.log. I’ll keep investigating.

I have searched around some more but got nowhere. Is there a log level somewhere that should be enabled?

As you have the API working, could you share OS and software version details of your system so I have a known good configuration to try?

I realize from your profile that supporting phpList is a service you offer, and I really appreciate the help you provide on the forums.

@brorme I’m testing the API on my desktop with LInux Mint, Apache, etc, nothing special.

You could try adding error reporting in the api.php file, which might help in getting more output, but i don’t know whether that is disabled elsewhere

error_reporting(-1);

The API has limited functionality, and the RESTAPI plugin is probably going to be what you need to use.

There are instructions I didn’t notice for enabling api logging here, but I don’t see any log files being generated in the phplist directory and there’s still nothing in system or apache logs. I also added error_reporting(-1); to api.ini as you suggested. Maybe the errors are logged somewhere I didn’t check, do you know where that might be?

I’m willing to use the plugin, but the built in API is enough for me, I just need it to add subscribers.

Could the php version be at fault? I’m using 7.4.33.

@brorme Sorry but I don’t have any further suggestions.