Bulk custom field update


I'm using campaign monitor and its API to send out emails to around 15000 subscribers. Every week we select around 100 subscribers and send them a specific email (all other subscribers also receive another specific email).

Each week these 100 subscribers are different. So I though that I'll use a custom field, called Selected, that I'll set to False as default. Then I'll set Selected to True for the 100 selected subscriber for that week. 2 segments (one for Selected=true and one for Selected=false) would do the job to send out these 2 different email campaigns every week.

But the problem is to change that custom field every week, the only solution I have so far is to update all 100 subscribers one by one and set Selected to true, send the emails and do the same to set the custom field to false. I didn't test that yet but thought it's not the best option.

Best option would be to be able to do a API call like:
UPDATE subscribers SET Selected=true WHERE subscribers.Id IN (list of the 100 selected subscribers)

What I understood this is not possible with the API. Am I right?
Has anyone any suggestion to find a better solution than the update one by one?

Thanks for your help,

mikemanger, 5 years ago

Hey P'titSuisse,

As far as I can tell there is no 'one-step' way of bulk updating subscribers using the API. BUT with a bit of coding you can easily get all active subscribers in a list using the API then individually update each one (in your case 'flipping a coin' to see if they are selected or not) until you have 100 new subscribers.

You will need to device a way of picking the new subscribers (I would work out the probability e.g. 100/15000 then loop until I have enough) but if you want the subscribers to be different each time you will either need to keep a list in your own database OR you could store another custom field for 'already selected'.

Ptitsuisse, 5 years ago

Hi Mike,

Thanks for your answer. The subscriber selection is done in our own database, so each time I want to send out a campaign I know the list of the 100 subscribers that are selected.

What I did so far is looping through the 100 selected subscribers and each time update the custom field. But this timeout most of time. Sometimes we have 500 selected subscriber so this will not work.

The code I use so far but times out:
    foreach ($selectedSubscribers as $subscriber ){

        $wrap = new CS_REST_Subscribers($list, $API);
        $result = $wrap->update( $subscriber->user_email , array(
            'CustomFields' => array(
                    'Key' => 'Selected',
                    'Value' => 1
        if($result->was_successful()) {
            echo "Subscriber updated with code ".$result->http_status_code;
        } else {
            echo 'Subscriber update failed with code '.$result->http_status_code."\n<br /><pre>";
            echo '</pre>';

Does anyone know a way to do that in only 1 API call?

Thanks for your help.

EDIT: by changing max_execution_time and adding ob_flush(); and flush(); in the loop it works (I've tested 200 subscribers), but a nicer way to do that with API would be great!

Ptitsuisse, 5 years ago

The final and best method to do this is to use the "Importing many subscribers" function (http://www.campaignmonitor.com/api/subscribers/#importing_subscribers).

This function also updates current subscribers if the email is already in the list. So you can update 1000 subscribers in 1 API call including custom fields.

Thanks to Campaign Monitor support for their help on that.

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free