Trying to save 2 custom fields via API

Hi guys, I'm trying to submit 2 custom fields via the API. I'm doing so through my short script like this:

// include subscriber api class
require_once ('/path/to/createsend-php/csrest_subscribers.php');

if ($form_id == 1) {
    // Define country
    $d_country = $form_data['element_15'];     
    // Format Date of birth
    $d_dob = $form_data['element_4_3'] . '/' . $form_data['element_4_2'] . '/' . $form_data['element_4_1'];
    $wrap = new CS_REST_Subscribers('MY API KEY', 'MY LIST ID');
    $result = $wrap->add(array(
        'EmailAddress' => $form_data['element_2'],
        'Name' => $form_data['element_3'],
        'CustomFields' => array(
                'Key' => 'Country',
                'Value' => $d_country
                'Key' => 'DateofBirth',
                'Value' => $d_dob
        'Resubscribe' => true

I can save the Country custom field with no problem, but I'm not having any luck with the DateofBirth custom field. What am I doing wrong?

I'm a complete noob - please respond as if you're speaking to a grade schooler :)

Phil Phil, 5 years ago


Date formats are always tricky, so you need to arrange element_4_3, element_4_2, and element_4_1 in a format that our parsing code can understand. It's hard to tell from your code, but I'm guessing they're a bit twisted up somewhere.

The safest way to represent a date as far as we're concerned is YYYY-MM-DD, ie:
* four-digit year first
* two-digit month next (ie february is 02, not 2, and definitely not FEB or February)
* two-digit day (ie, the 5th is 05)
* all three separated by a dash (normal minus sign)

That would mean that today is represented as 2011-03-31

Admittedly, i can't find any of this in the subscriber documentation, but i might look into getting that fixed. Hopefully that solves your problem, but if it doesn't, please drop us an email (with enough account information so we know who you are, and maybe the form you're using) and we'll look into it.

blogjunkie, 5 years ago

Hi Phil, thanks for taking the time to answer. I tried separating the date numbers with dashes as you suggested but that didn't work too. Does this mean this is a bug in the API? This is the first time I've experimented with any APIs that I automatically assumed that the mistake was with my code.

By the way, I separated them with slashes originally because of this Help article:

Phil Phil, 5 years ago


Yes, there's nothing as helpful as conflicting information, is there. Either the slashes or the dashes should work. As long as it's year-month-day, but you do want to be careful to ensure that placeholder zeros (03 instead of 3) are present. Dates have definitely been working in the API, so it's likely the problem is specific to your account or code.

If you send in a support request with some account specific information we can actually check the API logs and see what's coming in and how it matches your list information.

blogjunkie, 5 years ago

Thanks Phil, that will help with debugging. Cheers

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