Invalid argument in ctctWrapper

Regular Participant

Invalid argument in ctctWrapper

I'm using the PHP wrapper provided in the Dev Network.  Yesterday it was working fine -- listing my events as desired.  Today I'm receiving the following error:

 

Warning: Invalid argument supplied for foreach() in/home/content/99/6955199/html/castalia/wp-content/themes/castalia/ctctWrapper.php on line2962

 

I just downloaded the wrapper again and uploaded it to my site.  The only settings I changed in the wrapper are the APIKey, path, username and password.  

 

Can you tell me why this is no longer working?

11 REPLIES 11
Employee

Hi,

 

That is the part of the wrapper where starts to grab the content out of the XML.  This typically happens when the wrong parameters are passed into it.  Can you provide me with some of the code that you are using to pass through the wrapper?

 

Thank You,

Ryan Davis
Quality Engineer
Regular Participant

Here's the code I'm using to retrieve the events and display them:

 

 

include_once('ctctWrapper.php');

$data = new EventCollection();

$events = $data->listEvents();

 

foreach($events[0] as $event)

{

$status = $event->getStatus();

if ($status=='ACTIVE'){

 

$link = $event->getLink();

$title = $event->getTitle();

$oeidk = str_replace('/ws/customers/ondina/events/','',$link);

$startdate = new DateTime($event->getStartDate());

$enddate = new DateTime($event->getEndDate());

$date =  new DateTime($event->getStartDate());

$date = $date->format('Y-m-d h:s');

$weekday = date('l', strtotime($date));

 

print '<a href="/castalia/courses/course-details?oeidk='.$oeidk.'">'.$event->getName().'</a><br />';

print ''.$weekday.'s -- '.$startdate->format('h:s a').' - '.$enddate->format('h:s a').'<br />';

print ''.$startdate->format('F d').' - '.$enddate->format('F d, Y').'<br />';

print '<i>'.$event->getDescription().'</i><br />';

print '<br />';

 

}

}

 

Thanks.

Regular Participant

Actually, it looks like I'm receiving a 500 error from the API.  I just printed the array returned when the ctctWrapper returns from attempting to establish a connection.  

 

Code:

$utility = new Utility();

$return = $utility->httpGet($utility->getApiPath() . '/ws/customers/'. $utility->getLogin() .'/events');

print_r($return);

 

Returns:

Array ( [xml] => [info] => Array ( [url] => https://api.constantcontact.com/ws/customers/ondina/events [content_type] => [http_code] => 500 [header_size] => 0 [request_size] => 322 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 3.575343 [namelookup_time] => 3.2E-5 [connect_time] => 3.09507 [pretransfer_time] => 3.399938 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 3.575322 [redirect_time] => 0 ) [error] => The requested URL returned error: 500 ) 

 

Account username = 'ondina'

 

Thanks!

 

Hello,

 

I was able to recreate the fact that there may be an issue with the events collection in the ctct wrapper.  I am going to take a look at this now.

 

We do have a new library though, that definitely works, and also has better documentation.  Please take a look at it here.  There is also a wiki, with specific documentation to the event collection here.

 

If you have any questions please let me know.

Benjamin Soder
NOC Analyst
Constant Contact
Regular Participant

The new library isn't fixing the problem for me either.

 

If I try basic authentication then I receive the following:  "Constant Contact HTTP Request Exception: HTTP Status 500".

If I try oauth authentication then I receive the following: "OAuth Exception: Username ondina not found in datastore Constant Contact HTTP Request Exception: HTTP Status 401 - Invalid token"

 

Here's the code I'm using for testing purposes:

 

   include_once('ConstantContact.php');   

$username = 'ondina';   

$password = 'xxxxxxxxx';   

$apiKey = 'xxxx-xxxx-xxxx-xxxx-xxxx';   

$consumerSecret = 'xxxxx';       

//$ConstantContact = new ConstantContact('basic', $apiKey, $username, $password);    

$ConstantContact = newConstantContact('oauth', $apiKey, $username, $consumerSecret);   

$events = $ConstantContact->getEvents();   

print_r($events);

 

I think the problem must be related to my account itself.  Even when I try to access the API through the browser (https://api.constantcontact.com/ws/customers/ondina/events) and pass APIKey + % + username with my password, I receive a 500 error back.  

 

Is there any solution for this today?  I have to demo the site to the client tomorrow.

 

 

Hi AlyciaD,

 

I have looked into your issue and it looks like there may be a defect with our API with getting a list of events.  We are currently working on a  fix right now but as a work around you can go into your account and restore any deleted events.  By doing so you should not receive any 500 errors. 

 

Thank you,

Ryan Davis
Quality Engineer
Regular Participant

I can't do that.  Those events were test events and need to be permanently removed before we go live with our site.  Is there any way someone at CC could permanently remove those events so they no longer crash the API?

Hello,

 

Currently the only work around for this defect is to restore the events.  However, our engineers are aware how important this is, and are working to correct this problem as soon as possible.  Once the defect has been fixed, I will post an update here letting you know that it has been resolved.

 

If you have any questions please let me know.

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Regular Participant

Thanks Benjamin.  I can confirm that restoring the events has fixed the error in ctctWrapper.  

 

Can you give me any idea of a timeframe for an actual fix?  A week?  A month?  I just need to know what sort of timeline to relay to my client.


Thanks again.

Hi,

 

We currently do not have a time frame but we are working diligently to get this issue resolved.


Thank You,

 

Ryan Davis
Quality Engineer

Update: We released a hot fix yesterday morning and we verified that it resolves this problem.  We also fixed an issue with Updated times in the Events API as well so all Updated times are correct now.  Thanks for your patience and reporting this!

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page