Mailchimp API v3.0 "status":"subscribed" always results in "status":"pending"

1.9k Views Asked by At

I am trying to subscribe a user to a list using the Mailchimp API and for some reason it keeps submitting the status as "pending" even though I have it set to "subscribed". I am trying to directly subscribe the user without prompting the conformation email.

Code:

$data = [
    'email'     => '[email protected]',
    '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;
}

Response:

{
    "id": "44848d9005a4ed1d5272c10e46031670",
    "email_address": "[email protected]",
    "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"
    }]
}
2

There are 2 best solutions below

3
jhut89 On

There are a number of things that could be going on here, but you might want to make sure that the account your API key belongs to does not have any MailChimp compliance related events preventing you from directly subscribing addresses.

0
Shanil Sasikumar On

The 'single opt-in methods' may be disabled for your account. You can see the reason in your account page. Use proper and valid emails for your contact list. If you violate this, the bounce rate will increase and that will leads to the disabling of 'single opt-in methods'. Going forward, all subscribers must complete the double opt-in process before they can be added to your list.