Custom Field Values Emptied By Subsequent Updates

Hello,

I am developing an application that makes heavy use of the PHP CMBase wrapper method subscriberAddWithCustomFields().

I am finding that if a list has defined custom fields foo, bar, and baz and I post a subscriberAddWithCustomFields() request with values for all 3 and then later with a value for just one of the three the other two previously set values are erased.

My post does not have empty values.

Example, setting two fields

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <Subscriber.AddWithCustomFields xmlns="http://api.createsend.com/api/">
        <ApiKey>xxx</ApiKey>
        <ListID>xxx</ListID>
        <Email>fred@xxx.com</Email>
        <Name>David Martin</Name>
        <CustomFields>
            <SubscriberCustomField>
                <Key>birthday</Key>
                <Value>yes</Value>
            </SubscriberCustomField>
            <SubscriberCustomField>
                <Key>foods</Key>
                <Value>Broccoli</Value>
            </SubscriberCustomField>
        </CustomFields>
    </Subscriber.AddWithCustomFields>
</soap:Body>
</soap:Envelope>

Check on CM and birthday and foods show values.

So I post again with just an update to foods:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <Subscriber.AddWithCustomFields xmlns="http://api.createsend.com/api/">
        <ApiKey>xxx</ApiKey>
        <ListID>xxx</ListID>
        <Email>fred@xxx.com</Email>
        <Name>David Martin</Name>
        <CustomFields>
            <SubscriberCustomField>
                <Key>foods</Key>
                <Value>Chocolate</Value>
            </SubscriberCustomField>
        </CustomFields>
    </Subscriber.AddWithCustomFields>
</soap:Body>
</soap:Envelope>

And now I have an updated value at CM for foods and an empty value for birthday.  What am I doing wrong?  I don't see any special update methods.  Am I required to post values for all custom fields when updating?

The behavior is not mentioned here: http://www.campaignmonitor.com/api/method/subscriber-addwithcustomfields/

Help would be most appreciated!

David Martin

davidh, 7 years ago

Yes, you need to specify the existing custom field values when updating a subscriber with subscriberAddWithCustomFields, otherwise the original values will be cleared. If you need to you can get the existing values using getSingleSubscriber.

This is to provide a way for custom field values to be deleted. We have discussed an option to leave the existing fields alone. Anyone who would really like to see that reply to this thread and we will discuss it further.

jerrygarciuh, 7 years ago

It would definitely make me happier if I could update without clobbering the existing data.

A LOT of frustration and wasted money could have been spared if your documentation mentioned this "feature" of clearing custom field data.

http://www.campaignmonitor.com/api/method/subscriber-add-and-resubscribe-with-custom-fields/

http://www.campaignmonitor.com/api/method/subscriber-addwithcustomfields

jerrygarciuh, 7 years ago

Ok, per the CM response above you need to use the getSingleSubscriber call which is not provided in CMBase.php so I made the function you will need: click here

davidh, 7 years ago

Thanks for the update to CMBase.PHP, that is great. I have also updated the documentation to make it clear how the custom fields will be treated.

jerrygarciuh, 7 years ago

Thanks!

jerrygarciuh, 7 years ago

By the way David,  did you see my post re Data structure returned by Subscribers.GetSingleSubscriber issue?  I am confused that the data is not nested in the same way it must be provided.

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