CampaignMonitor::createClient PHP Method

createClient() public method

Creates a client. Returns the client ID when succesful or false if the call failed
public createClient ( string $companyName, string $country, string $timezone ) : string
$companyName string The client company name.
$country string This client’s country.
$timezone string Client timezone for tracking and reporting data.
return string
    public function createClient($companyName, $country, $timezone)
    {
        // fetch the country list
        $countries = $this->getCountries();
        $timezones = $this->getTimezones();
        // check if $country is in the allowed country list
        if (!in_array($country, $countries)) {
            throw new CampaignMonitorException('No valid country provided');
        }
        // check if $timezone is in the allowed timezones list
        if (!in_array($timezone, $timezones)) {
            throw new CampaignMonitorException('No valid timezone provided');
        }
        // set parameters
        $parameters['CompanyName'] = (string) $companyName;
        $parameters['Country'] = (string) $country;
        $parameters['Timezone'] = (string) $timezone;
        // try and create the record
        return (string) $this->doCall('clients', $parameters, 'POST');
    }

Usage Example

Beispiel #1
0
 /**
  * Attempts to create a client
  *
  * @return	mixed
  * @param	array $record		The client record to create.
  */
 private function createClient($record)
 {
     // get the account settings
     $url = BackendModel::getModuleSetting($this->getModule(), 'cm_url');
     $username = BackendModel::getModuleSetting($this->getModule(), 'cm_username');
     $password = BackendModel::getModuleSetting($this->getModule(), 'cm_password');
     // create a client
     try {
         // fetch complete list of timezones as pairs
         $timezones = BackendMailmotorCMHelper::getTimezonesAsPairs();
         // init CampaignMonitor object
         $cm = new CampaignMonitor($url, $username, $password, 10);
         // create client
         $clientID = $cm->createClient($record['company_name'], $record['contact_name'], $record['contact_email'], $record['country'], $timezones[$record['timezone']]);
         // store ID in a setting
         if (!empty($clientID)) {
             BackendModel::setModuleSetting($this->getModule(), 'cm_client_id', $clientID);
         }
     } catch (Exception $e) {
         // add an error to the email field
         $this->redirect(BackendModel::createURLForAction('settings') . '&error=campaign-monitor-error&var=' . $e->getMessage() . '#tabSettingsClient');
     }
 }