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.

Blank Event object

Highlighted
Occasional Contributor

Blank Event object

I'm using the ctctWrapper.php file to retrieve a list of Events.  I've successfully retrieved an array of events.  If I print_r the array, I see data in it.

 

When I try to create an Event object from an array item, the resulting Event object has null values throughout.  I can't seem to populate the Event object properly.  

 

Here's the code:

 

$data = new EventCollection();

$events = $data->listEvents();

foreach ($events as $item) {

$event= new Event($item);

print var_dump($event); //currently just dumping the object...all values NULL

}

 

Thanks.

3 REPLIES 3
Highlighted
Employee

Re: Blank Event object

Hello,

 

I believe the issue that you are running into is that the Events object that is returned when looking at the listEvents function returns both an array for the events, and an array for the next page of events, as all collections in our API return a set of 50 objects at a time.

 

Here is an example of code that you can use which will list all of your events as objects in an array.

 

<?php
    include_once("ctctWrapper.php");
    $data = new EventCollection();
    $events = $data->listEvents();
    print var_dump($events);
?>


If you have any questions regarding this please let me know.

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Contributor

Re: Blank Event object

How do I access an individual Event object?  I need to loop through and display details on each event in the array.  I'm missing something in the next step.  Thanks!

 

Highlighted
Employee

Re: Blank Event object

Hello,

 

If you want to loop through each event, you would need to do this:

 

<?php
    include_once("ctctWrapper.php");
    $data = new EventCollection();
    $events = $data->listEvents();
    foreach($events[0] as $event)
    {
        print_r ($event);
    }
?>


You could replace the print_r function for what you would want to do for each instance of $event.

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact
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