Making Rest API call

Ok. Excuse my ignorance.

Now that I’ve gotten the curl working, how exactly is it that I would make a call to it to add an email/name/data to a list/database for PHPList? Is there a specific curl command I can use to add a subscriber to a list? I ask because the link to examples in the manual doesn’t work.

“To demonstrate how to use the API some example clients are available in different programming languages. See the REST API Client Examples repository for details.”

The link in that line goes right back to the same page its on - no examples.

I did find something on GitHub, but it appears to reference it’s own code. I’m guessing that we should be able to call the API directly with some php or curl to do something like the above request?

Here’s a simple example on GitHub:

When you consume the other calls in your implementation make sure to use the basic auth header.
Let me know if you have other questions.

1 Like

I tried that code. I got it to work once, then it didn’t work again. First question I have is: Shouldn’t it be referencing the API instead of installing a whole new framework, as this has a “vendor” folder that seems to be required for that example (and I put it on my server and got it to work once, but couldn’t get it to work again).

It seems like we should be referencing the API installed by PHPList, no?

Probably the session token expired.
That’s simply an example of a client implementation that uses the phpList REST API, but developers can choose to implement it in whatever programming language or framework works best for them.
You can take a look at API Blueprint for the complete documentation of the supported requests.

Ok, I’ve got your Rest API example working every time. I was making a call to an incorrect URI.

Here’s the next question: When I’m adding a subscriber, how to do I make sure they go onto a specific list - I can’t seem to find a way to do it with your subscriberRequest function.

2nd Question: is there a way to add a particular attribute as well, when adding a subscriber?

1 Like

Look at post above. Please.

Great that it’s working!

They are not yet supported.

That’s disappointing. Any time line on when that might happen?

Hi Jody - it looks alike I am in the same situation as you. I would like to use phplists for a non profit association to send newsletter to our members. I would like to invite each member automatically during the registration process.
Right mow I’m completely lost - as I do not even get the example from xheni returning me anything.
What did you do to get it the Rest API example working every time?
Any hint would be appreciated.
My phpList is on revision 3.4.2 and when I try to create a session I get an error code 400 - “Empty JSON data”

1 Like

Make sure that the content-type of your request is set to Json.

Thanks for your help - but for my very simple tests with Postman I made sure, that the content-type is set to Json but the return is always empty code 400 ‘Empty JSON data’
I am also playing around with the example from Xheni Myrtaj. The funny thing is, that it partially worked for phpList 3.4.1 - but after updating to 3.4.2 I cannot even start a session, getting error code 500 ‘Internal Server Error’

Did you check that the rest api is still enabled after the update?

Hi D,

My server is running on NGINX. In another thread I was having trouble connecting to the API. I’m not sure if you’re running NGINX, but it was all of a simple rewrite line that fixed my issue - to direct the API to know where to look for the page/file. That’s because NGINX doesn’t use .htaccess files. Code wise it was as I mentioned a single line compared to all the code the .htaccess file has in the example.

@samtuke - YES, after the update I enabled the rest api again - but no success.

@jodywhitesides - Our association server is hosted from a German provider - so I do not really know what is behind the ‘wall’. mod_rewrite is enabled there and it supports .htaccess files as well.
However - I did something similar with the phpscheduleit/booked api and that is working like a charme.
I am really struggeling with phpList 3.4.2

Make sure that your URL is correct.

Hello xheni - how can I use wrong URLs by using your example?

I have taken your example code, changed the domain to the one of our server, like

//Please replace the following values with yours.
$loginname = ‘my admin login’;
$password = ‘my admin password’;
$base_uri = ‘’;

and so on.

When I start the script

try {
$response = $client->request(‘POST’, $base_uri . ‘/sessions’, [
‘form_params’ => [
‘login_name’ => $loginname,
‘password’ => $password,
} catch (\GuzzleHttp\Exception\GuzzleException $e) {

it already throws the exception:
{“code”:500,“message”:“Internal Server Error”}

Any help would be highly appreciated.

I tried your example with incorrect credentials and I get
GuzzleHttp\Exception\ClientException: Client error:POST in a401 Unauthorizedresponse: {"code":401,"message":"Unauthorized"}
which means the url is correct.
Try adding echo $e; in catch (\GuzzleHttp\Exception\GuzzleException $e) {

1 Like

Hi xheni,

I tried this already with correct credentials and get:
Server error: POST resulted in a 500 Internal Server Error

Seems like you must be using a different request to Xheni.

Folks - I am still not able to make a successfull REST API call.
So I went back to a very basic, pragmatic testing condition by just checking if the API is enabled and working properly. I tried authenticating a new session from my Mac terminal using the curl command-line utility.

curl --request POST --url --header 'Content-Type: application/json' --data '{"login_name": "myuser","password": "mypassword"}'

When applying wrong credentials for myuser and mypassword it throws:

When applying correct credentials for myuser and mypassword it throws:
“code”:500,“message”:“Internal Server Error”

So the connection seem to work - but causing ‘Server Problems’ with valid credentials.

My environment:
phplist v 3.4.2 installed at Hoster - running PHP 7.3
REST API enabled in public_html/lists/base/config/config_modules.yml
my admin account is set to ‘Super User’
phplist application is processing correctly

Has anyone any hint for me where to look or what to do in order to get this REST API working?