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.

Trouble migrating

Highlighted
Occasional Advisor

Trouble migrating

Hi there,


I'm not able to migrate properly, and I thought I updated the code properly.  Can you help?  Here's the code:


Thank you,


Andrew


    if (empty($errmsg)) {

            $output='';

            if (LOGFILE && LOG_LEVEL == 2) error_log(date('Y-m-d H:i:s') .

                           ' Request data: ' . $entry .

                           "\n", 3, LOGFILE);



            //$list_resp = $ct->FindContactList("Friends");   

       $request =  "https://api.constantcontact.com/ws/customers/".CC_USERNAME."/contacts";

       $session = curl_init($request);

       // Set up Digest authentication - username and password.

       $userNamePassword = CC_APIKEY."%".CC_USERNAME.":".CC_PASSWORD;

       curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

       curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 0);

       curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);

       curl_setopt($session, CURLOPT_FOLLOWLOCATION  ,1);

       curl_setopt($session, CURLOPT_POST, 1);

       curl_setopt($session, CURLOPT_POSTFIELDS , $entry);

       curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));

       curl_setopt($session, CURLOPT_HEADER, 0);   // Do not return headers

       curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);

       $response = curl_exec($session);

       curl_close($session);

       if (!$response) {

               // curl failed, create error message

                $output .= "

                    <h1>Oops!</h1>

                    <p>There was an error trying to connect to the server. <br />

                    Please go <strong><a href=\"#\" onClick=\"history.go(-1)\">BACK</a></strong> and try again later.</p>

                    ";

 


 

7 REPLIES 7
Highlighted
Solution Provider

Same here, please help!!!!!!

My code is exactly the same as above somebody please help -

Highlighted
Moderator

Are you receiving any error

Are you receiving any error messages when attempting to send your data through?  Your code is set up correctly on the php side, most likely there is a curl or server setting that is not correct.  An error message will point us in a better directiong.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Advisor

Where do I look?

Hi there,


Where do I look for an error?  The only error I get is the one coded into the PHP file:  


"Oops!


There was an error trying to connect to the server.

Please go BACK and try again later."


 


If you can describe what I can do to look, that would be great.  I'd also do a screen share with someone if that could resolve it quickly.


Thank you,


andrew

Highlighted
Moderator

Looking at your code snippet

Looking at your code snippet more, though it seems incomplete as it doesn't check for error codes, you only should see that error oops message if there is no response code to the curl_exec command.  This would indicate that the operation failed to connect to Constant Contact entirely.  If we sent back an error message, $response would not be empty, it would contain an error code and message form us and you would not see that message at all.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Advisor

so what's next? what do I do?

Hi Dave,


What's my next step then?


Thanks


Andrew

Highlighted
Occasional Advisor

correction

Hi Dave,


I just realized my form is working when a new email address is entered.  The error I showed you is happening when an existing email address is entered.   What do I need to adjust to have it show the right message when the existing email address is entered?


Thanks!


Andrew

Highlighted
Moderator

Existing contacts must be

Existing contacts must be handled differently.  A POST is only used for creating in REST based APIs.  To update, you will need to do a PUT with a well formed update to the contact URI, not the contacts collection.  For more information on how to do this, please see the Contacts Collection documentation.

Dave Berard
Senior Product Manager, Constant Contact
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