protected function loadFullDetails() { $interface = new CS_REST_Lists($this->ID, $this->apiKey); $result = $interface->get(); $response = $this->parseResult($result); $this->populateFrom($response); }
public function get_list($data = array()) { require_once APPPATH . 'vendor/campaignmonitor/csrest_lists.php'; $auth = array('api_key' => \Config::get('details.api_key')); $client_id = \Config::get('details.client_id'); $list_id = \Config::get('details.list_id'); $list = new \CS_REST_Lists($list_id, $auth); return $list->get(); }
/** * Retrieves the lists via Campaign Monitor API and updates the data in DB. * @return string */ function get_campaign_monitor_lists($api_key, $name) { require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/createsend-php-4.0.2/csrest_clients.php'; require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/createsend-php-4.0.2/csrest_lists.php'; $auth = array('api_key' => $api_key); $request_url = esc_url_raw('https://api.createsend.com/api/v3.1/clients.json?pretty=true'); $all_clients_id = array(); $all_lists = array(); if (!function_exists('curl_init')) { return __('curl_init is not defined ', 'rapidology'); } // Get cURL resource $curl = curl_init(); // Set some options curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $request_url, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_USERPWD => $api_key . ':x')); // Send the request & save response to $resp $resp = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Close request to clear up some resources curl_close($curl); $clients_array = json_decode($resp, true); if ('200' == $httpCode) { $error_message = 'success'; foreach ($clients_array as $client => $client_details) { $all_clients_id[] = $client_details['ClientID']; } if (!empty($all_clients_id)) { foreach ($all_clients_id as $client) { $wrap = new CS_REST_Clients($client, $auth); $lists_data = $wrap->get_lists(); foreach ($lists_data->response as $list => $single_list) { $all_lists[$single_list->ListID]['name'] = $single_list->Name; $wrap_stats = new CS_REST_Lists($single_list->ListID, $auth); $result_stats = $wrap_stats->get_stats(); $all_lists[$single_list->ListID]['subscribers_count'] = sanitize_text_field($result_stats->response->TotalActiveSubscribers); $all_lists[$single_list->ListID]['growth_week'] = sanitize_text_field($this->calculate_growth_rate('campaign_monitor_' . $single_list->ListID)); } } } $this->update_account('campaign_monitor', sanitize_text_field($name), array('api_key' => sanitize_text_field($api_key), 'lists' => $all_lists, 'is_authorized' => 'true')); } else { if ('401' == $httpCode) { $error_message = __('invalid API key', 'rapidology'); } else { $error_message = $httpCode; } } return $error_message; }
public function updateWebhooks($vars) { require_once 'lib/csrest_lists.php'; $listIds = array_keys($this->getLists()); $wh = array(); $whActive = array(); $whDeactive = array(); foreach ($listIds as $listId) { if ($savedWh = $this->getDi()->store->get(self::CM_STORE_KEY_LIST . $listId)) { $wh[] = $savedWh; continue; } $wrap = new CS_REST_Lists($listId, array('api_key' => $this->getConfig('api_key'))); $result = $wrap->create_webhook(array('Events' => array(CS_REST_LIST_WEBHOOK_SUBSCRIBE, CS_REST_LIST_WEBHOOK_DEACTIVATE, CS_REST_LIST_WEBHOOK_UPDATE), 'Url' => ROOT_SURL . '/misc/misc-' . $this->getId(), 'PayloadFormat' => CS_REST_WEBHOOK_FORMAT_JSON)); if ($result->was_successful()) { $this->getDi()->store->set(self::CM_STORE_KEY_LIST . $listId, $result->response); $wh[] = $result->response; } else { throw new Am_Exception_InternalError("Cannot create webhook for {$listId} by reason: {$result->http_status_code}"); } } $this->debugLog("updateWebhooks: webhooks created " . join(',', $wh) . " for lists " . join(',', $listIds)); foreach ($vars as $k => $v) { if (!preg_match("/^newsletter.campaignmonitor.webhook_(.*)\$/", $k, $match)) { continue; } $listId = $match[1]; $webhookId = $this->getDi()->store->get(self::CM_STORE_KEY_LIST . $listId); if ($v) { if ($this->getDi()->store->get(self::CM_STORE_KEY_WEBHOOK . $webhookId)) { $whActive[] = $webhookId; continue; } $wrap = new CS_REST_Lists($listId, array('api_key' => $this->getConfig('api_key'))); $result = $wrap->activate_webhook($webhookId); if ($result->was_successful()) { $this->getDi()->store->set(self::CM_STORE_KEY_WEBHOOK . $webhookId, 1); $whActive[] = $webhookId; } else { throw new Am_Exception_InternalError("Cannot activate webhook {$webhookId} for {$listId} by reason: {$result->http_status_code}"); } } else { if (!$this->getDi()->store->get(self::CM_STORE_KEY_WEBHOOK . $webhookId)) { $whDeactive[] = $webhookId; continue; } $wrap = new CS_REST_Lists($listId, array('api_key' => $this->getConfig('api_key'))); $result = $wrap->deactivate_webhook($webhookId); if ($result->was_successful()) { $this->getDi()->store->delete(self::CM_STORE_KEY_WEBHOOK . $webhookId); $whDeactive[] = $webhookId; } else { throw new Am_Exception_InternalError("Cannot deactivate webhook {$webhookId} for {$listId} by reason: {$result->http_status_code}"); } } } $this->debugLog("updateWebhooks: webhooks activated " . join(',', $whActive) . "; deactivated " . join(',', $whDeactive)); return null; }
private static function get_custom_fields($list_id) { self::include_api(); $api = new CS_REST_Lists($list_id, self::get_api_key()); //getting list of all Campaign Monitor merge variables for the selected contact list $response = $api->get_custom_fields(); if (!$response->was_successful()) { return array(); } $custom_field_objects = $response->response; $custom_fields = array(array("FieldName" => "Email Address", "Key" => "[email]"), array("FieldName" => "Full Name", "Key" => "[fullname]")); foreach ($custom_field_objects as $custom_field) { $custom_fields[] = get_object_vars($custom_field); } return $custom_fields; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get_active_subscribers('Added since', 1, 50, 'email', 'asc'); //$result = $wrap->get_active_subscribers(date('Y-m-d', strtotime('-30 days')), // page number, page size, order by, order direction); echo "Result of GET /api/v3/lists/{ID}/active\n<br />"; if ($result->was_successful()) { echo "Got subscribers\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
public static function cmdr_mass_update() { global $cmdr_fields_to_hide; $cmdr_user_fields = (array) unserialize(base64_decode(get_option('cmdr_user_fields'))); if (!class_exists('CS_REST_Lists')) { require_once CMDR_PLUGIN_PATH . 'campaignmonitor-createsend-php/csrest_lists.php'; } if (!class_exists('CS_REST_Subscribers')) { require_once CMDR_PLUGIN_PATH . 'campaignmonitor-createsend-php/csrest_subscribers.php'; } $auth = array('api_key' => get_option('cmdr_api_key')); $wrap_l = new CS_REST_Lists(get_option('cmdr_list_id'), $auth); $wrap_s = new CS_REST_Subscribers(get_option('cmdr_list_id'), $auth); // Update custom fields $missing_fields = $cmdr_user_fields; $result = $wrap_l->get_custom_fields(); if (!$result->was_successful()) { self::$error = $result->response; return false; } if (is_array($result->response)) { foreach ($result->response as $key => $field) { $k = str_replace('[', '', str_replace(']', '', $field->Key)); if (in_array($k, $missing_fields)) { unset($missing_fields[array_search($k, $missing_fields)]); } } } foreach ($missing_fields as $key => $field) { if (!in_array($field, $cmdr_fields_to_hide)) { $result = $wrap_l->create_custom_field(array('FieldName' => $field, 'Key' => $field, 'DataType' => CS_REST_CUSTOM_FIELD_TYPE_TEXT)); if (!$result->was_successful()) { self::$error = $result->response; return false; } } } // Update users $missing_users = array(); $u = get_users(); foreach ($u as $key => $value) { $missing_users[] = $value->user_email; } $result = $wrap_l->get_active_subscribers('', 1, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i = 2; while (count($result->response->Results)) { if (!empty($result->response->Results) && is_array($result->response->Results)) { foreach ($result->response->Results as $key => $subscriber) { set_time_limit(60); $user = get_user_by('email', $subscriber->EmailAddress); if ($user) { $args = array(); if (trim($user->first_name . ' ' . $user->last_name) != trim($subscriber->Name)) { $args['Name'] = $user->first_name . ' ' . $user->last_name; } $custom_values = array(); foreach ($subscriber->CustomFields as $field) { $k = str_replace('[', '', str_replace(']', '', $field->Key)); $custom_values[$k] = $field->Value; } foreach ($cmdr_user_fields as $key => $field) { if (!in_array($field, $cmdr_fields_to_hide)) { if (empty($custom_values[$field]) || trim($custom_values[$field]) != trim(get_user_meta($user->ID, $field, true))) { // We export scalar values only if (is_scalar(get_user_meta($user->ID, $field, true))) { $args['CustomFields'][] = array('Key' => $field, 'Value' => get_user_meta($user->ID, $field, true)); } else { $args['CustomFields'][] = array('Key' => $field, 'Value' => ''); } } } } if (count($args)) { $result_tmp = $wrap_s->update($user->user_email, $args); if (!$result_tmp->was_successful()) { self::$error = $result_tmp->response; return false; } } } if (in_array($subscriber->EmailAddress, $missing_users)) { unset($missing_users[array_search($subscriber->EmailAddress, $missing_users)]); } } } $result = $wrap_l->get_active_subscribers('', $i, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i++; } // Get bounced and unsubscribed users $unsubscribed = array(); $result = $wrap_l->get_unsubscribed_subscribers('', 1, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i = 2; while (count($result->response->Results)) { foreach ($result->response->Results as $key => $subscriber) { $unsubscribed[] = $subscriber->EmailAddress; } $result = $wrap_l->get_unsubscribed_subscribers('', $i, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i++; } $bounced = array(); $result = $wrap_l->get_bounced_subscribers('', 1, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i = 2; while (count($result->response->Results)) { foreach ($result->response->Results as $key => $subscriber) { $bounced[] = $subscriber->EmailAddress; } $result = $wrap_l->get_bounced_subscribers('', $i, 1000); if (!$result->was_successful()) { self::$error = $result->response; return false; } $i++; } $subscribers = array(); foreach ($missing_users as $key => $user_email) { if (!in_array($user_email, $unsubscribed) && !in_array($user_email, $bounced)) { // Subscriber does not exist, let's add him $user = get_user_by('email', $user_email); if ($user) { $args = array('EmailAddress' => $user->user_email, 'Name' => $user->first_name . ' ' . $user->last_name, 'CustomFields' => array()); foreach ($cmdr_user_fields as $key => $field) { if (!in_array($field, $cmdr_fields_to_hide)) { // We export scalar values only if (is_scalar(get_user_meta($user->ID, $field, true))) { $args['CustomFields'][] = array('Key' => $field, 'Value' => get_user_meta($user->ID, $field, true)); } else { $args['CustomFields'][] = array('Key' => $field, 'Value' => ''); } } } $subscribers[] = $args; } } } while (count($subscribers)) { set_time_limit(60); $subscribers1000 = array(); for ($i = 0; $i < 1000; $i++) { $subscribers1000[] = array_shift($subscribers); if (!count($subscribers)) { break; } } $result = $wrap_s->import($subscribers1000, true); if (!$result->was_successful()) { self::$error = $result->response; return false; } } return true; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get_deleted_subscribers('Deleted Since', 1, 50, 'email', 'asc'); //$result = $wrap->get_bounced_subscribers(date('Y-m-d', strtotime('-30 days')), // page number, page size, order by, order direction); echo "Result of GET /api/v3/lists/{ID}/deleted\n<br />"; if ($result->was_successful()) { echo "Got subscribers\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists(NULL, 'Your API Key'); $result = $wrap->create('Lists Client ID', array('Title' => 'List Title', 'UnsubscribePage' => 'List unsubscribe page', 'ConfirmedOptIn' => true, 'ConfirmationSuccessPage' => 'List confirmation success page', 'UnsubscribeSetting' => CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS)); echo "Result of POST /api/v3/lists/{clientID}\n<br />"; if ($result->was_successful()) { echo "Created with ID\n<br />" . $result->response; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); /* * The Events array must contain a combination of * CS_REST_LIST_WEBHOOK_SUBSCRIBE * CS_REST_LIST_WEBHOOK_DEACTIVATE * CS_REST_LIST_WEBHOOK_UPDATE * * The payload format must be one of * CS_REST_WEBHOOK_FORMAT_JSON or * CS_REST_WEBHOOK_FORMAT_XML */ $result = $wrap->create_webhook(array('Events' => array(CS_REST_LIST_WEBHOOK_SUBSCRIBE, CS_REST_LIST_WEBHOOK_DEACTIVATE), 'Url' => 'http://www.example.com/webhook_receiver.php', 'PayloadFormat' => CS_REST_WEBHOOK_FORMAT_JSON)); echo "Result of POST /api/v3.1/lists/{ID}/webhooks\n<br />"; if ($result->was_successful()) { echo "Created with ID\n<br />" . $result->response; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->test_webhook('Webhook ID'); echo "Result of POST /api/v3/lists/{ID}/webhooks/{WHID}/test\n<br />"; if ($result->was_successful()) { echo "Test was successful"; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->delete_custom_field('Custom field key'); echo "Result of DELETE /api/v3/lists/{ID}/{Key}\n<br />"; if ($result->was_successful()) { echo "Deleted with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->get_unconfirmed_subscribers('Added since', 1, 50, 'email', 'asc'); //$result = $wrap->get_active_subscribers(date('Y-m-d', strtotime('-30 days')), // page number, page size, order by, order direction); echo "Result of GET /api/v3.1/lists/{ID}/unconfirmed\n<br />"; if ($result->was_successful()) { echo "Got subscribers\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
$output = "["; foreach ($lists->response as $list) { $output .= "{\"ListID\": \"{$list->ListID}\", "; $output .= "\"Name\": \"{$list->Name}\""; $output .= "},"; } //subs the last comma $output = substr($output, 0, -1); $output .= "]"; echo $output; } } elseif ($req == "list" && isset($_GET["list_id"])) { //View active subscribers from a list(list_id) $list_id = $_GET["list_id"]; //Get the appropriate wrapper to View active subscribers $wrap_lists = new CS_REST_Lists($list_id, $auth); $active_subscribers = $wrap_lists->get_active_subscribers(); //JSON manipiulation of the response $output = "["; foreach ($active_subscribers->response->Results as $subscriber) { $output .= "{\"EmailAddress\": \"{$subscriber->EmailAddress}\", "; $output .= "\"Name\": \"{$subscriber->Name}\""; $output .= "},"; } //subs the last comma $output = substr($output, 0, -1); $output .= "]"; echo $output; } elseif ($req == "addSub" && isset($_GET["list_id"])) { //Add a new subscriber to the list $list_id = $_GET["list_id"];
/** * Return an array of Campaign Monitor fields for the specified list. * * @param string $list_id The list ID. * * @return array */ public function get_custom_fields($list_id) { $this->include_api(); $api = new CS_REST_Lists($list_id, $this->get_key()); $custom_fields = array(array('label' => esc_html__('Email Address', 'gravityformscampaignmonitor'), 'name' => 'email', 'required' => true), array('label' => esc_html__('Full Name', 'gravityformscampaignmonitor'), 'name' => 'fullname')); $response = $api->get_custom_fields(); if (!$response->was_successful()) { return $custom_fields; } $custom_field_objects = $response->response; foreach ($custom_field_objects as $custom_field) { $name = str_replace('[', '', $custom_field->Key); $name = str_replace(']', '', $name); $custom_fields[] = array('label' => $custom_field->FieldName, 'name' => $name); } return $custom_fields; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->get_segments(); echo "Result of GET /api/v3.1/lists/{ID}/segments\n<br />"; if ($result->was_successful()) { echo "Got custom fields\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->get_stats(); echo "Result of GET /api/v3.1/lists/{ID}/stats\n<br />"; if ($result->was_successful()) { echo "Got list stats\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get_webhooks(); echo "Result of GET /api/v3/lists/{ID}/webhooks\n<br />"; if ($result->was_successful()) { echo "Got list webhooks\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get_bounced_subscribers('Bounced Since', 1, 50, 'email', 'asc'); //$result = $wrap->get_bounced_subscribers(date('Y-m-d', strtotime('-30 days')), // page number, page size, order by, order direction); echo "Result of GET /api/v3/lists/{ID}/bounced\n<br />"; if ($result->was_successful()) { echo "Got subscribers\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get_unsubscribed_subscribers('Unsubscribed Since', 1, 50, 'email', 'asc'); //$result = $wrap->get_bounced_subscribers(date('Y-m-d', strtotime('-30 days')), // page number, page size, order by, order direction); echo "Result of GET /api/v3/lists/{ID}/unsubscribed\n<br />"; if ($result->was_successful()) { echo "Got subscribers\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->update(array('Title' => 'List Title', 'UnsubscribePage' => 'List unsubscribe page', 'ConfirmedOptIn' => true, 'ConfirmationSuccessPage' => 'List confirmation success page')); echo "Result of PUT /api/v3/lists/{ID}\n<br />"; if ($result->was_successful()) { echo "Updated with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->get_custom_fields(); echo "Result of GET /api/v3.1/lists/{ID}/customfields\n<br />"; if ($result->was_successful()) { echo "Got custom fields\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->update_field_options('[CustomFieldKey]', array('Option 1', 'Option 2'), true); echo "Result of PUT /api/v3/lists/{ID}/customfields/{fieldkey}/options\n<br />"; if ($result->was_successful()) { echo "Updated with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists(NULL, 'Your API Key'); $result = $wrap->create('Lists Client ID', array('Title' => 'List Title', 'UnsubscribePage' => 'List unsubscribe page', 'ConfirmedOptIn' => true, 'ConfirmationSuccessPage' => 'List confirmation success page')); echo "Result of POST /api/v3/lists/{clientID}\n<br />"; if ($result->was_successful()) { echo "Created with ID\n<br />" . $result->response; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->delete_webhook('Webhook ID'); echo "Result of DELETE /api/v3.1/lists/{ID}/webhooks/{WHID}\n<br />"; if ($result->was_successful()) { echo "Deleted with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->update(array('Title' => 'List Title', 'UnsubscribePage' => 'List unsubscribe page', 'ConfirmedOptIn' => true, 'ConfirmationSuccessPage' => 'List confirmation success page', 'UnsubscribeSetting' => CS_REST_LIST_UNSUBSCRIBE_SETTING_ALL_CLIENT_LISTS, 'AddUnsubscribesToSuppList' => true, 'ScrubActiveWithSuppList' => true)); echo "Result of PUT /api/v3.1/lists/{ID}\n<br />"; if ($result->was_successful()) { echo "Updated with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); /* * The DataType parameter must be one of * CS_REST_CUSTOM_FIELD_TYPE_TEXT * CS_REST_CUSTOM_FIELD_TYPE_NUMBER * CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTONE * CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTMANY * CS_REST_CUSTOM_FIELD_TYPE_DATE * CS_REST_CUSTOM_FIELD_TYPE_COUNTRY * CS_REST_CUSTOM_FIELD_TYPE_USSTATE * */ $result = $wrap->create_custom_field(array('FieldName' => 'Custom field name', 'DataType' => CS_REST_CUSTOM_FIELD_TYPE_MULTI_SELECTONE, 'Options' => array('First option', 'Second Option'))); echo "Result of POST /api/v3/lists/{ID}/customfields\n<br />"; if ($result->was_successful()) { echo "Created with ID\n<br />" . $result->response; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->get(); echo "Result of GET /api/v3/lists/{ID}\n<br />"; if ($result->was_successful()) { echo "Got list details\n<br /><pre>"; var_dump($result->response); } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); } echo '</pre>';
<?php require_once '../../csrest_lists.php'; $auth = array('access_token' => 'your access token', 'refresh_token' => 'your refresh token'); $wrap = new CS_REST_Lists('List ID', $auth); $result = $wrap->activate_webhook('Webhook ID'); echo "Result of PUT /api/v3.1/lists/{ID}/webhooks/{WHID}/activate\n<br />"; if ($result->was_successful()) { echo "Activated with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }
<?php require_once '../../csrest_lists.php'; $wrap = new CS_REST_Lists('List ID', 'Your API Key'); $result = $wrap->delete(); echo "Result of DELETE /api/v3/lists/{ID}\n<br />"; if ($result->was_successful()) { echo "Deleted with code\n<br />" . $result->http_status_code; } else { echo 'Failed with code ' . $result->http_status_code . "\n<br /><pre>"; var_dump($result->response); echo '</pre>'; }