Created
June 5, 2017 09:03
-
-
Save chetansatasiya/3ae9d2152487490c734bcf1884ec9fe1 to your computer and use it in GitHub Desktop.
MailChimp API 3.0 and WordPress HTTP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Enter MailChimp API key and List Id. | |
$api_key = 'YOUR API KEY'; | |
$list_id = 'YOUR LIST ID'; | |
$dc = substr($api_key,strpos($api_key,'-')+1); // datacenter, it is the part of your api key - us5, us8 etc | |
$args = array( | |
'headers' => array( | |
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key ) | |
) | |
); | |
$response = wp_remote_get( 'https://'.$dc.'.api.mailchimp.com/3.0/lists/'.$list_id, $args ); | |
$body = json_decode( $response['body'] ); | |
if ( $response['response']['code'] == 200 ) { | |
echo $body->stats->member_count; | |
} else { | |
echo '<b>' . $response['response']['code'] . $body->title . ':</b> ' . $body->detail; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment