Having trouble bulk adding subscribers - import PHP wrapper

Has anyone ever used the import function from the php wrapper code.

For our application, our team only has access to import names and emails from an excel file which is why those values are in arrays. The custom fields below are just sample text and not our actual names.

With the below code, I received an error code 400 (Failed to deserialize your request.
Fields in error: subscribers), and can't pinpoint which array is having trouble. Would anyone be able to assist?

Custom fields being built:

$customFieldArray = array(
array("field1", $se_region),
array("field2", $ShowJAgaby),
array("field3", $ShowRCohen),
array("field4", $ShowADonsky)

Making array to match fields:

$addFieldsToList = array();
    foreach (array_combine($names, $emails) as $name => $email) {
       $addFieldsToList[] = array('Name' => $name,'Email Address' => $email, 'CustomFields' => $customFieldArray);

Call to import:

$wrap = new CS_REST_Subscribers($cm_listID, $apikey);
    $result = $wrap->import(array($addFieldsToList), false);

I have verified that the list is being created, and custom fileds were added before starting the above code.

jtesolin jtesolin, 1 year ago

Was able to fix. Forgot to name the custom fields properly:

$customFieldArray = array(
array('Key' => 'field1','Value' => $value1),
array('Key' => 'field2','Value' => $value2),
array('Key' => 'field3','Value' => $value3),
array('Key' => 'field4','Value' => $value4)

If you make it like the above everything works.

Edit: fixed formatting of code tag content.

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