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.)

/* LOOP START */
$subscriber = array();
$customFields = array();

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

$subscriber[0]['Key']='EmailAddress'; //SECOND ARRAY
$subscriber[0]['Value']='bob@bob.com';
$subscriber[1]['Key']='Name';
$subscriber[1]['Value']='';

array_push($subscriber,$customFields);

array_push($thedata,$subscriber);

/*LOOP END*/

$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) {
  ["Code"]=>
  int(400)
  ["Message"]=>
  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.
NULL

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.
Andreas

Phil Phil, 5 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(
    array(
      'Key' => 'CustomFieldOne',
      'Value' => 'Field Value One'
    ),
    array(
      'Key' => 'CustomFieldTwo',
      'Value' => 'Field Value Two'
    ))
);

array_push($subscribers, $subscriber);

Hope that helps

unfold, 5 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.
Andreas

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