我从未使用过Mailchimp API,我想知道是否有人可以通过示例向我展示如何使用此endpoint创建新列表?我以后如何才能获得此列表的ID(仅使用列表名称),以便我可以添加订阅者?
由于
答案 0 :(得分:3)
使用PHP和cURL:
<?php
$apikey = '<api-key>'; // replace with your API key
$dc = '<data-center>'; // replace with your data center
$data = array( // the information for your new list--not all is required
"name" => $name,
"contact" => array (
"company" => $company,
"address1" => $address1,
"address2 => $address2,
"city" => $city,
"state" => $state,
"zip" => $zip,
"country" => $country,
"phone" => $phone
),
"permission_reminder" => $permission_reminder,
"use_archive_bar" => $archive_bars,
"campaign_defaults" => array(
"from_name" => $from_name,
"from_email" => $from_email,
"subject" => $subject,
"language" => $language
),
"notify_on_subscribe" => $notify_subs,
"notify_on_unsubscribe" => $notify_unsubs,
"email_type_option" => $type,
"visibility" => $visibility
);
$data = json_encode($data); // API requires JSON objects
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$dc.".api.mailchimp.com/3.0/lists/"); // ../lists/ URL to create new list resource
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTREQUEST, true); // declare request is POST type
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set POST data
curl_setopt($ch, CURLOPT_USERPWD, "user:".$apikey); // HTML Basic Auth
$output = curl_exec($ch); // execute and capture response
curl_close($ch);
print_r($output); // display API response
?>
为了获得API的简洁方法,我强烈建议您在MailChimp API Playground中玩游戏。