如何使用 Mailchimp API v.3 创建新的邮件列表并获取其 ID?
How to create new mailing list using Mailchimp API v.3 and get its id?
我从未使用过 Mailchimp API,我想知道是否有人可以通过示例向我展示如何使用此 endpoint 创建新列表?我以后如何才能获得此列表的 ID(仅使用列表名称),以便我可以向其添加订阅者?
谢谢
使用 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 中游玩。
我从未使用过 Mailchimp API,我想知道是否有人可以通过示例向我展示如何使用此 endpoint 创建新列表?我以后如何才能获得此列表的 ID(仅使用列表名称),以便我可以向其添加订阅者?
谢谢
使用 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 中游玩。