Improperly formatted XML

Highlighted
Occasional Participant

Improperly formatted XML

When using the API to create a new campaign, first an attempt is made to gather all lists.  I don't know if this is unique to our data but this code is failing.  The value for $call is:


https://api.constantcontact.com/ws/customers/skipperbuds/lists

 


            $return = $this->doServerCall($call);

            $parsedReturn = simplexml_load_string($return);

            $call2 = '';


In our case $parsedReturn is string of 46 spaces causing issues further down stream.  I beleive that the Php function simplexml_load_string is failing because the input - $return is incorrectly formatted.  It is missing a few elements.  I have attached a text file with the resultant XML.


Is there anything I can do?


 


 


 

Buddy Peacock

2 REPLIES 2
Highlighted
CTCT Employee

Re: Improperly formatted XML

I am not seeing 46 spaces as the XML you attached. The only issue I am experiencing using the simplexml_load_string function on the XML you attached is that there is no closing </feed> tag. Once I add that the XML is taken without an issue.


Does this code below produce an error for you?


$username = 'USERNAME';

$password = 'PASSWORD';

$apikey = 'APIKEY';



$requestLogin = $apikey . '%' . $username . ':' . $password;



$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/'.$username.'/lists');

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch, CURLOPT_USERPWD, $requestLogin);

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

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

curl_setopt($ch, CURLOPT_FAILONERROR, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');



$return = curl_exec($ch);

$return = curl_getinfo($ch);

$return = curl_error($ch);



$parsedReturn = simplexml_load_string($return);

print_r($parsedReturn);

David J

Highlighted
Occasional Participant

my issue was an I D 10 T error....

Sorry for the waste of time....

Buddy Peacock

Developer Portal

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

Visit Page

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