Mailchimp API v3.0“status”:“subscribed”总是导致“status”:“pending”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mailchimp API v3.0“status”:“subscribed”总是导致“status”:“pending”相关的知识,希望对你有一定的参考价值。

我正在尝试使用Mailchimp API将用户订阅到列表,并且出于某种原因,即使我将其设置为“已订阅”,它也会继续将状态提交为“待处理”。我试图直接订阅用户而不提示确认电子邮件。

码:

$data = [
    'email'     => 'eggsscramble42343@gmail.com',
    'status'    => 'subscribed',
    'firstname' => 'john',
    'lastname'  => 'doe'
];

syncMailchimp($data);



function syncMailchimp($data) {
    $apiKey = ###;
    $listId = ###;

    $memberId = md5(strtolower($data['email']));
    $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
    $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;

    $json = json_encode([
        'email_address' => $data['email'],
        'status'        => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
        'merge_fields'  => [
            'FNAME'     => $data['firstname'],
            'LNAME'     => $data['lastname']
        ]
    ]);

    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);



    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    return $httpCode;
}

响应:

{
    "id": "44848d9005a4ed1d5272c10e46031670",
    "email_address": "eggsscramble42343@gmail.com",
    "unique_email_id": "37a0bec0fb",
    "email_type": "html",
    "status": "pending",
    "merge_fields": {
        "FNAME": "john",
        "LNAME": "doe"
    },
    "stats": {
        "avg_open_rate": 0,
        "avg_click_rate": 0
    },
    "ip_signup": "",
    "timestamp_signup": "",
    "ip_opt": "50.62.176.151",
    "timestamp_opt": "2017-01-05T17:20:22+00:00",
    "member_rating": 2,
    "last_changed": "2017-01-05T18:40:57+00:00",
    "language": "",
    "vip": false,
    "email_client": "",
    "location": {
        "latitude": 0,
        "longitude": 0,
        "gmtoff": 0,
        "dstoff": 0,
        "country_code": "",
        "timezone": ""
    },
    "list_id": "ec3297395e",
    "_links": [{
        "rel": "self",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670",
        "method": "GET",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
    }, {
        "rel": "parent",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members",
        "method": "GET",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/CollectionResponse.json",
        "schema": "https://us5.api.mailchimp.com/schema/3.0/CollectionLinks/Lists/Members.json"
    }, {
        "rel": "update",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670",
        "method": "PATCH",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json",
        "schema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PATCH.json"
    }, {
        "rel": "upsert",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670",
        "method": "PUT",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json",
        "schema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/PUT.json"
    }, {
        "rel": "delete",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670",
        "method": "DELETE"
    }, {
        "rel": "activity",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670/activity",
        "method": "GET",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Activity/Response.json"
    }, {
        "rel": "goals",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670/goals",
        "method": "GET",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Goals/Response.json"
    }, {
        "rel": "notes",
        "href": "https://us5.api.mailchimp.com/3.0/lists/ec3297395e/members/44848d9005a4ed1d5272c10e46031670/notes",
        "method": "GET",
        "targetSchema": "https://us5.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Notes/CollectionResponse.json"
    }]
}
答案

您的帐户可能会停用“单一选择加入方式”。您可以在帐户页面中查看原因。为您的联系人列表使用正确有效的电子邮件。如果您违反此规定,跳出率将会增加,这将导致禁用“单一选择加入方式”。展望未来,所有订阅者必须完成双重选择加入流程才能将其添加到您的列表中。

另一答案

这里有许多事情可以发生,但您可能希望确保您的API密钥所属的帐户没有任何与MailChimp合规相关的事件,从而阻止您直接订阅地址。

以上是关于Mailchimp API v3.0“status”:“subscribed”总是导致“status”:“pending”的主要内容,如果未能解决你的问题,请参考以下文章

连接到 MailChimp v3.0 API

使用 Mailchimp api v3.0 将订阅者添加到分段

使用 .Net 调用 MailChimp API v3.0

如何获取 mailchimp API v3.0 上的所有列表?

使用maleorang v3.0 java api发送mailchimp活动

使用 MailChimp API v3.0 创建新的订阅者验证错误