I am trying to ingrate mailchimp API API link with woocommerce. I am trying to add user in mailchimp. Before adding the user in mailchimp list , i searching the user with getListMember method if user is not present in mailchimp list , i will add the user to list But if user exist in the list i will update the status. For searching the user i created a custom function getMemberInfo($email) i am calling this function before add user in mailchimp list
function getMemberInfo($email)
{
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => $GLOBALS['mailchimpAPI'],
'server' => $GLOBALS['mailchimpServer']
]);
$list_id = $GLOBALS['mailchimpListID'];
$subscriberHash = md5(strtolower($email));
try {
$response = $mailchimp->lists->getListMember($list_id, $subscriberHash);
//print_r($response);
if($response->status == 404)
{
return 0;
}else{
return 1;
}
} catch (MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
}
but i am getting the following error
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://usxx.api.mailchimp.com/3.0/lists/debxxxxxxxx/members/xxxxxxxxxd207ccxxxxxxx6a5d238` resulted in a `404 Not Found` response:
{"type":"https://mailchimp.com/developer/marketing/docs/errors/","title":"Resource Not Found","status":404,"detail":"The (truncated...)
in D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113
Stack trace:
#0 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true)
#5 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#7 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\promises\src\Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Client.php(123): GuzzleHttp\Promise\Promise->wait()
#10 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\mailchimp\marketing\lib\Api\ListsApi.php(4218): GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array)
#11 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\mailchimp\marketing\lib\Api\ListsApi.php(4207): MailchimpMarketing\Api\ListsApi->getListMemberWithHttpInfo('debxxxxxxxx', 'xxxxxxxxxd207ccxxxxxxx6a5d238...', NULL, NULL)
#12 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\mailchimp-api.php(80): MailchimpMarketing\Api\ListsApi->getListMember('debxxxxxxxx', 'xxxxxxxxxd207ccxxxxxxx6a5d238...')
#13 D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\functions.php(351): getMemberInfo('test1009@test...')
#14 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(303): save_my_account_page_custom_details(33)
#15 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#16 D:\xampp\htdocs\wpreg\wp-includes\plugin.php(470): WP_Hook->do_action(Array)
#17 D:\xampp\htdocs\wpreg\wp-content\plugins\woocommerce\includes\class-wc-form-handler.php(348): do_action('woocommerce_sav...', 33)
#18 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(303): WC_Form_Handler::save_account_details('')
#19 D:\xampp\htdocs\wpreg\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
#20 D:\xampp\htdocs\wpreg\wp-includes\plugin.php(470): WP_Hook->do_action(Array)
#21 D:\xampp\htdocs\wpreg\wp-includes\template-loader.php(13): do_action('template_redire...')
#22 D:\xampp\htdocs\wpreg\wp-blog-header.php(19): require_once('D:\\xampp\\htdocs...')
#23 D:\xampp\htdocs\wpreg\index.php(17): require('D:\\xampp\\htdocs...')
#24 {main}
thrown in D:\xampp\htdocs\wpreg\wp-content\themes\ljschildtheme\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113
Update
For adding the user i am using the flowing function.This function is working fine
function subscribeEmailToMailChimp($email,$fname,$lname)
{
$mailchimp = new \MailchimpMarketing\ApiClient();
$mailchimp->setConfig([
'apiKey' => $GLOBALS['mailchimpAPI'],
'server' => $GLOBALS['mailchimpServer']
]);
$list_id = $GLOBALS['mailchimpListID'];
try {
$response = $mailchimp->lists->addListMember($list_id, [
"email_address" => $email,
"status" => "subscribed",
"merge_fields" => [
"FNAME" => $fname,
"LNAME" => $lname
]
]);
//print_r($response);
} catch (MailchimpMarketing\ApiException $e) {
echo $e->getMessage();
}
}
Any Advice