AddAContact Failing

Highlighted
New Member

AddAContact Failing

I am testing the contact_form.html - AddAContact.php - Contact.php files andgetting the following. I have a valid username, password and API Key and modified these values in Contact.php. I am on GoDaddy hosting with PHP 5. No other mods but the login info and List_Name.

Warning: simplexml_load_string() : Entity: line 1: parser error : Start tag expected, '<' not found in /home/content/a/c/u/acurarl/html/contest/Contact.php on line 108

Warning: simplexml_load_string() : Error 401: Error reported: 401 in /home/content/a/c/u/acurarl/html/contest/Contact.php on line 108

Warning: simplexml_load_string() : ^ in /home/content/a/c/u/acurarl/html/contest/Contact.php on line 108

Warning: Invalid argument supplied for foreach() in /home/content/a/c/u/acurarl/html/contest/Contact.php on line 109

System Error Encountered!
Error

could not find valid list with the name Contest+Participants

the log file only gives the list error:
2009-03-04 11:40:25 Error could not find valid list with list name Contest+Participants
7 REPLIES 7
Highlighted
Moderator

AddAContact Error

The files you are referring to were written and provided by another Constant Contact customer and were designed to work in PhP 5.0+. Are you using PhP 4.0?

The other thing I would recommend checking is the list name to ensure there is a list in your account named "Contest Participants".
Dave Berard
Senior Product Manager, Constant Contact
Highlighted
New Member

Check for Existing Contact

Ok, I used some other code from elsewhere and can add a contact now successfully so moving on... I am using a form however that exisiting users will also be using so I need to check for the existing email first to avoid the 409 error. I saw the Querying page, but that only gives XML and not the PHP that I need to get it done. Here's what I'm using for a successful add:

/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////

$UN = "username";
$PW = "password";
$Key = "key";

$date = date("Y-m-d\TH:i:s");

$entry = <<


$date

data:,none
Contact


$email
$firstname
$lastname
ACTION_BY_CUSTOMER

END;

$entry .= ''."\n";

$entry .= <<




END;

// Initialize the cURL session
$request ="http://api.constantcontact.com/ws/customers/" . $UN . "/contacts";
$session = curl_init($request);

// Set up digest authentication
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;

// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
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, false); // Do not return headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, 1); // If you set this to 0, it will take you to a page with the http response

// Execute cURL session and close it
$response = curl_exec($session);
$httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);
curl_close($session);

if ($httpcode > 199 && $httpcode < 300)
{
echo "It works!!" ; // You might want GET the updated Contact and display it
}
else
{ echo " There is a Problem Error Code: ". $httpcode ; }

/////////////////////////////////////////////////////////////////

So can you tell me where to get some PHP to check first for an existing so that I can do an add or skip it? Thanks.
Highlighted
Solution Provider

RE: Check for Existing Contact

Here is Example of php code that checks to see if a contact Exist

<?php


$UN = "Username";

$PW = "Password";

$Key = "Key";

$Email = "Email@address.com"; // $_POST


strtolower($Email); // Make the string lowercase


// Initialize the curl session

$url ="http://api.constantcontact.com/ws/customers/" . $UN . "/contacts?email=".$Email ;

$UserKey = $Key . '%' . $UN . ':' . $PW ;

$session = curl_init($url);





curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

curl_setopt($session, CURLOPT_USERPWD, $UserKey);

curl_setopt($session, CURLOPT_FOLLOWLOCATION ,1);

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

curl_setopt($session, CURLOPT_HEADER, 0);

curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($session);

curl_close($session);



//echo $response ; use for Debugging



$pos = strpos($response , "entry") ;



if ($pos !== false )

{

// Contact found check to see if the contact is on the Do Not Mail List or Remove list

$UnsubscribeContact = strpos($response , "Do Not Mail") ; // Check if the contact is a unsubscribe contact

$Removed = strpos($response , "Removed") ; // Check if the contact is on the remove list

if ($UnsubscribeContact !== false || $Removed !== false)

{



// Insert Code to do a PUT



}

else

{

// Insert code to give option to update profile

}



}

else

{

// Contact Not Found insert your code to add contact



}


 


 


?>

Mike C Support Engineer, Constant Contact

Highlighted
New Member

I'm using goDaddy and have

I'm using goDaddy and have the exact same errors--all of them. I changed the file extension to .php5 so it would run under v.5, no change. I changed the default PHP language to 5, no change. What did you do to resolve this?
Highlighted
Occasional Participant

same problem

I'm using godaddy and have the same problem as described above. It will work about 50% of the time, but otherwise i get errors:
Warning: simplexml_load_string() : Entity: line 1: parser error : Start tag expected, '<' not found in /home/content/j/f/h/xxxxxxxx/html/contact/Contact.php on line 93

Warning: simplexml_load_string() : Error 500: SRVE0207E: Uncaught initialization exception thrown by servlet in /home/content/j/f/h/xxxxxxxx/html/contact/Contact.php on line 93

Warning: simplexml_load_string() : ^ in /home/content/j/f/h/xxxxxxxx/html/contact/Contact.php on line 93

Warning: Invalid argument supplied for foreach() in /home/content/j/f/h/xxxxxxxx/html/contact/Contact.php on line 94

Sometimes I will only get the error:
Error 500: SRVE0207E: Uncaught initialization exception thrown by servlet

And the other times I get no error and find the contact was added successfully.
Any idea how to fix this?
Occasional Participant

Same error here, also hosting

Same error here - also hosting on GoDaddy(PHP Version 5.2.5, libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.) I receive the following cURL response: bool(false). Not sure if it has anything to do with this: http://davidwalsh.name/godaddy-hosting-curl. However, GoDaddy states they no longer require proxy servers for outbound connections: http://help.godaddy.com/article/4764.

Highlighted
Occasional Participant

I was able to correct the

I was able to correct the problem by using Basic instead of Digest authentication. See: http://developer.constantcontact.com/doc/authenticationBasic.

Developer Portal

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

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured