Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with 'Add a new subscriber' in RestAPIclientSimpleExample.php #3

Open
dhaude opened this issue May 6, 2019 · 5 comments
Open

Comments

@dhaude
Copy link

dhaude commented May 6, 2019

Hi there,

today I started to play around with the example file 'RestAPIclientSimpleExample.php'.

Main iterest for me is the part 'Add a new subscriber'.

The first parts of the example is basically working - however for the 'Add a new subscriber' part I am getting the Error message:

Fatal error: Uncaught Error: Call to a member function getBody() on null

Has anyone out there got the 'Add a new subscriber' part correctly working?

@xh3n1
Copy link
Member

xh3n1 commented May 7, 2019

@dhaude Great to hear that you are playing around with the REST API,
I cannot reproduce this issue. What phpList version are you running

@dhaude
Copy link
Author

dhaude commented May 9, 2019

@xh3n1 - Thanks for your reply - I'm using phpList version 3.4.1
I plan to establish an automated 'Add a new subscriber' for a non profit association when new members get added to our system. Unfortunately with no success until now.
So any hint or example how to do that would be highly appreciated.

@xh3n1
Copy link
Member

xh3n1 commented May 13, 2019

This part of the code is an example of adding a new subscriber with hardcoded data that works for me. https://github.com/phpList/RestAPIclientSimpleExample/blob/master/RESTAPIphpListClient.php#L83-L99
I'm not sure how can I help without checking your code. Feel free to email me at xheni@phplist.com.

@LTepliakov
Copy link

LTepliakov commented Aug 20, 2019

Hi Dhaude,
looks I met with the same problem and seems I understand the reason.
Below is the full log that I got from the sample script:
Session key is: a52569951a5676794729db77e7c49e8b

List Info:

name : test
description : List for testing
creation_date : 2019-07-02T11:29:16+00:00
public :
category :
id : 1

Subscribers of test:

creation_date : 2019-07-02T11:29:16+00:00
email : leon@us.ibm.com
confirmed : 1
blacklisted :
bounce_count : 0
unique_id : 047355177e01fac11435bd3abda4b18f
html_email : 1
disabled :
id : 1

PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST http://localhost:8090/lists/api/v2/subscribers resulted in a 409 Conflict response:
{"code":409,"message":"Conflict"}

After the error message returned by PHP you can also see json reply from application.
It says about conflict.
In my case the reason of conflict was that the email address I was trying to add was already in subscriber list.

This sample script can not be run successfully twice.
The first time it adds the subscriber.
The second time it fails because subscriber already exists in the list.
And the script does not contain correct code to process exception caused by conflict, that's why you get this "PHP Fatal error".

@samtuke
Copy link

samtuke commented Aug 21, 2019

@LTepliakov Many thanks for sharing your solution!

Do either of you feel like patching the example code to prevent conflicting records and allow it to be run multiple times without error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants