CampaignMonitor::getSubscriber PHP Method

getSubscriber() public method

Returns the details of a particular subscriber, including email address, name, active/inactive status and all custom field data. If a subscriber with that email address does not exist in that list, an empty record is returned.
public getSubscriber ( string $email, string[optional] $listId = null ) : array
$email string The emailaddress.
$listId string[optional]
return array
    public function getSubscriber($email, $listId = null)
    {
        // stop here if no email was set
        if (!$email) {
            throw new CampaignMonitorException('No e-mail given.');
        }
        // set ID
        $listId = empty($listId) ? $this->getListId() : $listId;
        // set parameters
        $parameters['email'] = (string) $email;
        // make the call
        $record = (array) $this->doCall('subscribers/' . $listId, $parameters);
        // stop here if no record was set
        if (empty($record)) {
            return array();
        }
        // set values
        $results['email'] = $record['EmailAddress'];
        $results['name'] = $record['Name'];
        $results['date'] = $record['Date'];
        $results['status'] = $record['State'];
        // check if there are clickedlinks present
        if (empty($record['CustomFields'])) {
            return array();
        }
        // loop records
        foreach ($record['CustomFields'] as $field) {
            // set values
            $results['custom_fields'][$field['Key']] = $field['Value'];
        }
        // return the records
        return $results;
    }