Help setting timezone in create client api

I'm getting an error due to an improperly formatted time zone when creating a client via the api. The time zones I'm using are:

(GMT-05:00) Eastern Time (US & Canada)
(GMT-06:00) Central Time (US & Canada)
(GMT-07:00) Arizona
(GMT-07:00) Mountain Time (US & Canada)
(GMT-08:00) Pacific Time (US & Canada)
(GMT-09:00) Alaska
(GMT-10:00) Hawaii

These are presented to a user upon registration on my site and stored in my CMS database. I then have a variable called $timezone that pulls it out of the database to be used for the API.

What am I doing wrong?

shovels, 5 years ago

Can you post the code you're using to try and create the new client? i.e.

$objClient->create(array(
                    'CompanyName'   => $arrFormFields['CompanyName']['value'],
                    'ContactName'   => $arrFormFields['ContactName']['value'],
                    'EmailAddress'  => $arrFormFields['EmailAddress']['value'],
                    'Country'       => $arrFormFields['Country']['value'],
                    'Timezone'      => $arrFormFields['TimeZone']['value'],
                ));

Also post the code where you're outputting the form - You need to make sure you're returning the correct value when the form is submitted.

Not sure if it makes any difference, but when I'm submitting the values they are html encoded.

One thing that I did (also to improve performance) was to download the list of countries via the api, take the countries data and then hard-code it in my code as a string. I then use the 'exact' values as provided by the API, but without having to query CM every time the page loads.

lsilver, 5 years ago

Here is the code I'm using to create the client:

require_once 'campaign-monitor-api/csrest_clients.php';
$company = $account->field_company[0]['value'];
$name = $account->field_firstname[0]['value'] . '%20' . $account->field_lastname[0]['value'];
$email = $user->mail;
$timezone = $account->field_time_zone[0]['value'];
$wrap = new CS_REST_Clients(NULL, 'my api');
$result = $wrap->create(array(
    'CompanyName' => $company,
    'ContactName' => $name,
    'EmailAddress' => $email,
    'Country' => 'United States of America',
    'Timezone' => $timezone
));

The timezone is selected when they sign up in our CMS. I've tried using encoding for spaces and amperstands, as well as using spaces and amperstands themselves. Right now I'm using the key value below (along with the labels) that use encoding:

(GMT-05:00)%20Eastern%20Time%20(US%20%26%20Canada)|(GMT-05:00) Eastern Time (US & Canada)
(GMT-06:00)%20Central%20Time%20(US%20%26%20Canada)|(GMT-06:00) Central Time (US & Canada)
(GMT-07:00)%20Arizona|(GMT-07:00) Arizona
(GMT-07:00)%20Mountain%20Time%20(US%20%26%20Canada)|(GMT-07:00) Mountain Time (US & Canada)
(GMT-08:00)%20Pacific%20Time%20(US%20%26%20Canada)|(GMT-08:00) Pacific Time (US & Canada)
(GMT-09:00)%20Alaska|(GMT-09:00) Alaska
(GMT-10:00)%20Hawaii|(GMT-10:00) Hawaii

If I put in a specific timezone instead of using a variable (e.g. (GMT-09:00) Alaska versus $timezone), everything works correctly and the client is created. So it's definitely an issue with either how I'm storing the timezone in the database or how it's getting translated within the variable.

shovels, 5 years ago

Are you using urlencode? I think that 'might' be your problem. I only use htmlentities and it's working fine when submitted to the API

lsilver, 5 years ago

I have no clue. I'm really good at copying and pasting : ) But much of this is new to me. I'll check around my Drupal settings to see if I can figure out something. But if you have any suggestions on how to figure it out I'm all ears. Thanks for the help.

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098