Now that I’ve gotten the curl https://domain.com/lists/api/v2/sessions 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?
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?
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”
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’
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
I tried your example with incorrect credentials and I get GuzzleHttp\Exception\ClientException: Client error:POST https://makerspace-wi.de/lists/api/v2/sessionsresulted in a401 Unauthorizedresponse: {"code":401,"message":"Unauthorized"}
which means the url is correct.
Try adding echo $e; in catch (\GuzzleHttp\Exception\GuzzleException $e) {
}
I tried this already with correct credentials and get: Server error: POST https://makerspace-wi.de/lists/api/v2/sessions resulted in a 500 Internal Server Error
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.
When applying wrong credentials for myuser and mypassword it throws:
“code”:401,“message”:“Unauthorized”
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 all.inkl.com - 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?