The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

editSubscriber Error in PHP

Highlighted
New Member

editSubscriber Error in PHP

Hi all, I am looking for some much appreciated help with the editSubscriber function included in the cc_class PHP class.  I can add a subscriber just fine, but when I try to edit them, the request hangs and times out.  Any suggestions?  Code below.  Thanks!


------------


include_once('cc_class.php');

$ccOBJ = new ConstantContact();


       $listids = array();

        $listids = "http://api.constantcontact.com/ws/customers/USER/lists/2";



        $contact = $ccOBJ->getSubscriberDetails($txtEmail);

        $contactid = $contact;



        if ($contactid != "") {

        foreach($contact as $email_list) {

            array_push($listids, $email_list);

        }

        }



        $postFields = array();

        $postFields = $txtEmail;

        $postFields = $eformat;

        $postFields = $listids;

        $postFields = "ACTION_BY_CUSTOMER";



        $postFields = "Active";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields= "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";

        $postFields = "";





        if ($contactid != "") {

            $contactXML = $ccOBJ->createContactXML($contactid,$postFields);



            if (!$ccOBJ->editSubscriber($contactid, $contactXML)) {

                $error = true;

            } else {

                $error = false;

            }



        }

        else {

            $contactXML = $ccOBJ->createContactXML(null,$postFields);

            if (!$ccOBJ->addSubscriber($contactXML)) {

                $error = true;

            } else {

                $error = false;



            }

        }


 

7 REPLIES 7
Highlighted
Employee

We have noticed that

We have noticed that depending on your server configuration, the PUT statement may hang and eventually time-out. This is most likely due to an issue with your cURL instillation and can most likely be resolved by changing the cURL method option as seen below:


 


Original line:

curl_setopt($ch, CURLOPT_PUT, 1);

 

Update to:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");


 


This has resolved every report that we have taken to date however if you are still experiencing problems please let us know.

Dan H

Support Engineer, Constant Contact

Highlighted
New Member

Thanks very much, that fixed

Thanks very much, that fixed the timeout issue.  However, now my code is not modifying contact lists for subscribers.  If I run the code with a pre-existing subscriber from list 1, they are not also added to list 2.  The PHP code is above.  I also went ahead and dumped the XML code generated below.


Did the cc_class class generate malformed XML, or am I doing something else wrong?  Thanks for any help!


 


<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"><title>TitleNode</title><updated>2010-04-29T08:36:13+01:00</updated><author><name>CTCT Samples</name></author><id>http://api.constantcontact.com/ws/customers/mysite/contacts/2</id><summary type="text">Customer document</summary><content type="application/vnd.ctct+xml"><Contact xmlns="http://ws.constantcontact.com/ns/1.0/">Customer document<EmailAddress>john@adsemail.com</EmailAddress><FirstName></FirstName><LastName></LastName><MiddleName></MiddleName><CompanyName></CompanyName><JobTitle></JobTitle><OptInSource>ACTION_BY_CUSTOMER</OptInSource><HomePhone></HomePhone><WorkPhone></WorkPhone><Addr1></Addr1><Addr2></Addr2><Addr3></Addr3><City></City><StateCode></StateCode><StateName></StateName><CountryCode></CountryCode><PostalCode></PostalCode><SubPostalCode></SubPostalCode><Note></Note><EmailType>HTML</EmailType><ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/mysite/lists/2"/><ContactList id="http://api.constantcontact.com/ws/customers/mysite/lists/1"/></ContactLists></Contact></content></entry>


Called in PHP script above:
$contactXML = $ccOBJ->createContactXML($contactid,$postFields);

if (!$ccOBJ->editSubscriber($contactid, $contactXML)) {
$error = true;
} else {
$error = false;
}
Highlighted
Employee

The XML being generated is

The XML being generated is valid and when modified to match my credentials, it runs correctly in the REST client. As a result, the contact was successfully updated and now resides on multiple lists.


 


Perhaps the issue is with the logic that you use to actually process the update.


 


I noticed that you included more detailed code in a direct email to support. Let us continue the troubleshooting through that channel.

Dan H

Support Engineer, Constant Contact

Highlighted
New Member

Same problem

I am ecountering the same problem as jpatrick85. Calls to addSubscriber work correctly, but calls to editSubscriber fail. As previously recommended, I changed curl_setopt($ch, CURLOPT_PUT, 1); to: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); This resolved the timout errors, but changes are not still applied to the contact. The code I use with cc_class.php used to work correctly and has not been changed. The curl package was recently upgrade to curl-7.19.7-9.fc12.i686 (Fedora 12), but I'm not sure if this is when the calls to editSubscriber stopped working.

Highlighted
New Member

same problem x2

Same problem, definatley solved the timeout issue but still not editing.


This problem started yesterday in the AM without changes to code.


Please help!

Highlighted
Occasional Participant

Is there a solution to this

Is there a solution to this problem yet? Also, encountering this issue with Editing a subscriber.


 


I also had to make that change to the class file to fix the timeout issue.

Highlighted
Employee

editSubscriber error

I have have been unable to replicate the 400 errors that you have been receiving. From the information I gathered from the few posts on this issue, it appears that the people running into this issue are all using cURL 7.19.7. While I do not have an environment to test this particular version of cURL, I have tested 7.19.4 and 7.20.0 without an issue. If you have the ability to move away from this version of cURL for testing, I would recommend giving that a try to see if this resolves your issue, although it seems a bit odd that one particular cURL version is giving 400 errors while a newer and older version do not.


 


A 400 error usually means there is an issue with the content or structure of your XML. If the XML structure itself is fine, you may want to take a look at your character encoding, as improper encoding could still result in a 400 error even if the structure 'looks' correct. If you want to email your full code to our webservices support team, I would be happy to review your code and see if I am able to replicate the error you are receiving. However, it seems likely that a server configuration setting may be the cause of this issue.

David J

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured