Importing Subscribers

I want to update a custom field for several hundred subscribers via one request so i have to use the import function and pass the value FALSE on Resubscribe. I have tried using the sample that was provided with the api and everything worked like a breeze. However i am stuck with how to implement the data array (that will contain the email, the name and an array that will contain the custom field name and value.)

$subscriber = array();
$customFields = array();

$customFields['Key']='month'; // FIRST ARRAY

$subscriber[0]['Key']='EmailAddress'; //SECOND ARRAY




$thedata['Key'] = 'Resubscribe'; //THE FINAL ARRAY
$thedata['Value'] = 'false'; 

The error that i get when i pass the $thedata array into the import function is the following :

object(stdClass)#5 (2) {
  string(113) "Failed to deserialize your request.
Please check the documentation and try again.
Fields in error: subscribers"

The following emails failed to import correctly.

So can someone help me understand in plain english what the problem is and ways to fix it?
Any help would be very much appreciated.

Phil Phil, 6 years ago

Hi Andreas,

If you're looking for someone to debug your code it's best to paste the relevant sections of (anonymized) code in their entirety, rather than only a couple of bits.

But based on the way you've set up $thedata, it looks like you're not using the php wrapper correctly. When you call the import function, it should have two arguments. The first is an array of subscribers to be imported, and the second is the resubscribe boolean. In your case, something like:

$result = $wrap->import($subscribers, false);

Within your loop, each subscriber needs to be constructed as an associative array as per the examples, and then pushed into your $subscribers array:

$subscriber =  array(
  'EmailAddress' => 'Subscriber email',
  'Name' => 'Subscriber name',
  'CustomFields' => array(
      'Key' => 'CustomFieldOne',
      'Value' => 'Field Value One'
      'Key' => 'CustomFieldTwo',
      'Value' => 'Field Value Two'

array_push($subscribers, $subscriber);

Hope that helps

unfold, 6 years ago

Phil thank you for the swift response. i found out that the problem was that i was adding twice the boolean subscribe. Thank you for your time.

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free