2

MailChimp API を使用してユーザーをリストに登録した人がいるかどうか疑問に思っています。

私が達成しようとしているドキュメントから、それがどのように行われるのか疑問に思っています。

curl --request POST \
--url 'https://usX.api.mailchimp.com/3.0/lists' \
--user 'anystring:apikey' \
--header 'content-type: application/json' \
--data '{"name":"Freddie'\''s Favorite Hats","contact":{"company":"MailChimp","address1":"675 Ponce De Leon Ave NE","address2":"Suite 5000","city":"Atlanta","state":"GA","zip":"30308","country":"US","phone":""},"permission_reminder":"You'\''re receiving this email because you signed up for updates about Freddie'\''s newest hats.","campaign_defaults":{"from_name":"Freddie","from_email":"freddie@freddiehats.com","subject":"","language":"en"},"email_type_option":true}' \
--include

私の試みはこれでした:

$apiKey ='mykey';
$listID = 'id';
$email = 'my@email.com';
$data = array(
    'email_address' => $email,
    'status' => 'subscribed'
);

$body = json_encode($data);

$opts = array(
    'headers' => array(
        'Content-Type' => 'application/json',
        'Authorization' => 'apikey ' . $apiKey
    ),
    'body' => $body
);

$apiKeyParts = explode('-', $apiKey);
$shard = $apiKeyParts[1];

$url = '//' . $shard . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/';

$response = wp_remote_post( $url, $opts );

if ( is_wp_error( $response ) ) {
    $result = $response->get_error_message();
} else {
    // DEBUG
    $result = print_r($response, true);
}

return $result;

しかし、それは機能しませんでした。別の投稿 (「これを機能させることができました」) も見つけましたが、私にとっては false を返していました。

4

0 に答える 0