如何使用Mailchimp API v.3创建新的邮件列表并获取其id



我从未使用过Mailchimp API,我想知道是否有人可以通过示例向我展示如何使用此端点创建新列表?之后如何获得该列表的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中玩一玩。

相关内容

最新更新