Created
September 26, 2014 07:47
-
-
Save rotten77/5bc86630e270fda2561a to your computer and use it in GitHub Desktop.
Campaign Monitor - update subscriber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
*===================================================================== | |
* Campaign Monitor API | |
* PHP library: http://campaignmonitor.github.io/createsend-php/ | |
*/ | |
define('API_KEY', ''); | |
define('LIST_ID', ''); | |
include dirname(__FILE__) . '/createsend-php/csrest_subscribers.php'; | |
$wrap = new CS_REST_Subscribers(LIST_ID, API_KEY); | |
$subscriber = array(); | |
$subscriber['EmailAddress'] = ''; | |
$subscriber['Name'] = ''; | |
$subscriber['CustomFields'] = array(); | |
$subscriber['CustomFields'][] = array('Key' => 'CustomField', 'Value' => ''); | |
$values = array( | |
"Value 2", | |
"Value 5", | |
); | |
foreach($values as $value) { | |
$subscriber['CustomFields'][] = array('Key' => 'CustomFieldMulti', 'Value' => $value); | |
} | |
// Check if exists | |
$result = $wrap->get($subscriber['EmailAddress']); | |
if(!$result->was_successful()) { | |
// add new | |
$result = $wrap->add($subscriber); | |
} else { | |
// update | |
$result = $wrap->update($subscriber['EmailAddress'], $subscriber); | |
} | |
// Výsledek | |
if($result->was_successful()) { | |
echo 'OK'; | |
var_dump($result); | |
} else { | |
echo 'ERR: '.$result->http_status_code; | |
var_dump($result->response); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment