Update multi option select without loosing other selections

Hello!

Im trying to update subscribers custom field with type - CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTMANY

After updating users custom field I loose other selections that were selected previously.
Example (using PHP wrapper) :

First I update subscriber with this value

$result = $wrap->update('test@test.lv', array(
    'EmailAddress' => 'test@test.lv',
    'Name' => 'Martin Anger',
    'CustomFields' => array(
        array(
            'Key' => 'api_filter',
            'Value' => '4'
        )       
    ),
    'Resubscribe' => false
));

When I check subscriber details I can see that api_filter selected value is 4.

Then I run update again with different value

$result = $wrap->update('test@test.lv', array(
    'EmailAddress' => 'test@test.lv',
    'Name' => 'Martin Anger',
    'CustomFields' => array(
        array(
            'Key' => 'api_filter',
            'Value' => '3'
        )       
    ),
    'Resubscribe' => false
));

When I now check subscriber details I can see that api_filter selected value is 3. But value 4 is not selected anymore. Why is this? According to https://www.campaignmonitor.com/api/subscribers/#updating_a_subscriber
values are cleared only when I add additional parameter : Clear = true.

Only way I can update subscriber with multiple selected values is by adding array with all (even previously added) values.

I found similar question in forum, but there is no answer. Examples could not answer my question.

I'm doing something wrong or I have misunderstood the documentation? Is this a bug?

davidaf davidaf, 1 year ago

Hi Mungurs,

Sorry for the confusion there, the api docs aren't as explicit as they should be. So, the clear=true is only if you want to actually replace the current value with null. Otherwise, any value you pass will always replace the current value. If you want to add a value, you need to include both the current value and the new value in your call.

I hope that clears things up! I've made a note with our writers that the docs should be clearer in this regard, as it does cause confusion from time to time.


The Campaign Monitor Blog – HTML email smarts to go with your good looks

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