cancel
Showing results for 
Search instead for 
Did you mean: 

individual event registrant response structure different from API documentation

Honored Contributor

Re: individual event registrant response structure different from API documentation

Hello,

 

You should be able to get this working by using the following code.

 

Config.php:

            'eventspot_registrant' => 'eventspot/events/%s/registrants/%s',
            'eventspot_registrants' => 'eventspot/events/%s/registrants'

 

ListService.php:

/**
     * Get all contacts from an event list
     * @param string $accessToken - Constant Contact OAuth2 access token
     * @param string $eventId - event id for which to retrieve contacts
     * @return ResultSet of Contact objects
     */
    public function getRegistrantsFromEvent($accessToken, $eventId, $params = null)
    {
        echo $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.eventspot_registrants'), $eventId);
        $url = $this->buildUrl($baseUrl, $params);
        
        $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
        $body = json_decode($response->body, true);
        $registrants = array();
        foreach ($body['results'] as $registrant) {
            $registrants[] = Contact::create($registrant);
        }
        return new ResultSet($registrants, $body['meta']);
    }
    
    /**
     * Get all contacts from an event list
     * @param string $accessToken - Constant Contact OAuth2 access token
     * @param string $eventId - event id for which to retrieve contacts
     * @return Contact
     */
    public function getRegistrantFromEvent($accessToken, $eventId, $registrantId)
    {
        echo $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.eventspot_registrant'), $eventId, $registrantId);
        $url = $this->buildUrl($baseUrl, $params);
        
        $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
        $body = json_decode($response->body, true);
        $registrant = Contact::create($body);
        return $registrant;
    }

 

One thing that is very much worthy of note is that this implementation is using the Contact object as the data model instead of the Registrant data model. This is very important because the two are very different and will result in a large amount of registrant specific data being lost. It should be reasonably straight forward to implement a Registrant class based on the model of the Contact class from this document: http://developer.constantcontact.com/docs/eventspot-apis/registrants-resource.html

 

If you continue to have any problems with this, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Occasional Contributor

Re: individual event registrant response structure different from API documentation

You can view my version (with my added code) of the PHP API library here: https://www.dropbox.com/s/frsjbiire3oivim/ctct.zip?dl=0