Skip to content

Instantly share code, notes, and snippets.

@manosriglis
Last active February 18, 2016 09:11
Show Gist options
  • Select an option

  • Save manosriglis/0b0213c6a2aa907e38c5 to your computer and use it in GitHub Desktop.

Select an option

Save manosriglis/0b0213c6a2aa907e38c5 to your computer and use it in GitHub Desktop.
Duplicate campaign monitor lists with custom field definitions
<?php
require_once 'vendor/campaignmonitor/createsend-php/csrest_lists.php';
$sourceList = new CS_REST_Lists('LIST_ID', array('api_key' => 'API_KEY'));
$targetList = new CS_REST_Lists('LIST_ID', array('api_key' => 'API_KEY'));
$result = $sourceList->get_custom_fields();
foreach($result->response as $field){
$fieldArray = json_decode(json_encode($field), true);
if ($field->DataType == 'MultiSelectOne' || $field->DataType == 'MultiSelectMany'){
$fieldArray['Options'] = $fieldArray['FieldOptions'];
unset($fieldArray['FieldOptions']);
}
$result = $targetList->create_custom_field($fieldArray);
if ($result->was_successful()){
print "Field '".$field->FieldName."' created.\n";
}else{
print "Field '".$field->FieldName."' not created. ".$result->response->Message."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment