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?
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.
Support Engineer, Constant Contact
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.
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 - 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.
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 - 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?
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.
There is no server update that Constant Contact can do, the issue is with the configuration of curl on the sending server. Please follow these steps for more information:
During Constant Contact testing of php and curl, we have come across a limitation of the curl function. For more information and how to fix this issue, please see this forum post. Please note, it has been identified in the curl documentation forums that this is a common server configuration issue with curl and not an issue with the Constant Contact API.