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.

Problem with the new Authentication System

Highlighted
Occasional Participant

Problem with the new Authentication System

Hi


We use PHP to upload contact information periodically. I tried to change the relevant parts of the code but get the following error.


"Error! No response from server"


The PHP code snippet is given below.




$postVars = "activityType=SV_ADD&lists=" . urlencode("http://api.constantcontact.com/ws/customers/" . $ccusername . "/lists/37");
$postVars = $postVars . "&data=" . urlencode($fileContents);
$request =  "https://api.constantcontact.com/ws/customers/" . $ccusername . "/activities";
$session = curl_init($request);
$userNamePassword = $apikey . '%' . $ccusername . ':' . $ccpassword;
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_FOLLOWLOCATION  ,1);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS , $postVars);
curl_setopt($session, CURLOPT_HEADER, 0);
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
What am I missing?

thx

11 REPLIES 11
Highlighted
Employee

You code appears to be

You code appears to be formatted correctly from the snippet you provided. I can say that the problem could be with the variable '$fileContents' and what information it contains. Typically a 500 error is due to an issue with the API however it can also be returned if the XML is not formatted correctly.


 


I would recommend testing with a very simple action like adding one contact to one list . You may also want to verify that the url encoded string is correct.

Dan H

Support Engineer, Constant Contact

Highlighted
Occasional Participant

XML?

Oh, does the new setup require only XML? May be I missed that part of the documentation. Pl confirm.


BTW, the exact same code (with the exception of the https & CURLAUTH parameter) works just fine with the existing setup. We are sending a CSV file.


thx

Highlighted
Moderator

There is a difference between

There is a difference between a Create (POST) and an Update (PUT).  First off, you can not use the CURLOPT_POSTFIELDS for a PUT.  You must use an in file and pull your XML from a file to do the update.  There is a sample of how to do this posted here.


 


If you are uploading a csv file of multiple contacts, the Bulk Activity API may be best for you.  It is designed for doing large imports (25 or more generally) where some may be new and others may be updates.  This will take care of that part of the work for you so you do not have to worry about it on a large scale.  

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Is that right?

Dave - if you look at the code I've included in my 1st post, there is no PUT; it's all POST. Right? If so, where is the confusion between PUT & POST?


Also, I am already using the bulk activity API activityType=SV_ADD in that code. Am I not?


This has been working perfectly for so many months. Is there something else that needs to be considered / missing for your new server requirement.


It is so much hard to debug this thing because the response from the server just says "Error! No response from server"; nothing more.


thx

Highlighted
Moderator

Very sorry for the confusion,

Very sorry for the confusion, I didn't read your initial post and only your follow up from Dan.  


 


Your code looks correct for using Basic Authentication over https with the activities collection.   The fact you are not receiving a response from the server normally indicates a connection issue.  Have you tried sending the same data through the REST client to make sure everything is being encoded correctly? 


 


Are you able to run a GET on a URL through PHP as well?  It would be a good test of your server configuration to see if you can return a simple XML entry for any of the collections.  This will tell you if the problem is with your POST for the activity or your servers configuration.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Old Code Works.

Dave - the exact same lines of code without the https and with digest (auth) works perfectly fine. That's what is surprising and want to find out if there is something parameter needed or to be changed?


thx

Highlighted
Moderator

We are aware of a server

We are aware of a server configuration issue with Curl that may affect PHP users.  We are testing the scope of this issue as well as the potential fixes.  We hope to have a post up in the next couple hours that should resolve alot of the issues.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Participant

Thanks

Thanks for the update. Looking forward to a solution.

Highlighted
Occasional Participant

Is it ready?

Dave - is this server update done? I am still getting the exact same error.


Is there any change that I need to do to make this work with the new update?


thx

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