Add subscriber with Multi Option Custom Field in PHP

I'm implementing 'add a subscriber with custom fields', using PHP wrappers.
The array of custom fields in the following manner works for standard text fields. But does not work with multi option custom fields.

    'CustomFields' => array(
        array(
            'Key' => 'Field name',
            'Value' => 'Field Value'
        )

I have tried using the values of the checkboxes as Value, but it doesnt seem to work. Any ideas?

Thanks,
Gary

tobyb tobyb, 3 years ago

Hey Gary,

The value should be the option itself. While it's not clear, this is detailed in the documentation. Say you had a Custom Field called 'interests' with options of 'magic', 'romantic walks' and 'music' you could set the 'magic' and 'romantic walks' options with the JSON below (which I've grabbed from the documentation).

    {
      "Key": "interests",
      "Value": "magic"
    }
    {
      "Key": "interests",
      "Value": "romantic walks"
    }

For the PHP Wrapper you would use the following code:

    'CustomFields' => array(
        array(
            'Key' => 'interests',
            'Value' => 'magic'
        ),
        array(
            'Key' => 'interests',
            'Value' => 'romantic walks'
        )
    )
gary_tdg, 3 years ago
tobyb wrote:

For the PHP Wrapper you would use the following code:

    'CustomFields' => array(
        array(
            'Key' => 'interests',
            'Value' => 'magic'
        ),
        array(
            'Key' => 'interests',
            'Value' => 'romantic walks'
        )
    )

Hi Toby,

The value stored in interests is always 'romantic walks'. Why does it overwrite the first value?
I'd like to store both as comma separated values in campaign monitor, if both options are checked.
And if one is checked, only that one needs to go into campaign monitor.

Thanks,
Gary

tobyb tobyb, 3 years ago

Hi Gary,

Make sure that the 'interests' field has a DataType of 'MultiSelectMany' during creation (or check with this route). If it is then it sounds like something is going wrong. Get in touch with us via support at campaignmonitor.com and we can have a look at your fields and API calls.

gary_tdg, 3 years ago

Toby, I checked it using both methods you suggested. It has the desired datatype of MultiSelectMany. Going to shoot an email to support now.

Thanks,
Gary

Sign up for free.
Then send campaigns for as little as $9p/m

Create an account