We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Trouble migrating

andrewappel
Regular Participant

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
nibdesign
Regular Participant

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

DaveBerard
Moderator

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
andrewappel
Regular Participant

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

DaveBerard
Moderator

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
andrewappel
Regular Participant

Hi Dave,


What's my next step then?


Thanks


Andrew

andrewappel
Regular Participant

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

DaveBerard
Moderator

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