What is subscriberHash parameter in deleteListMember method of mailchimp-marketing plugin?

57 views Asked by At

When I need to add in laravel 10 app user to mailchimp I use addListMember method of https://github.com/mailchimp/mailchimp-marketing-php (v3.0) plugin

    $response = $this->getApiClient()->lists->addListMember($this->mailchimpListId, [
        "email_address" => $email,
        "status" => "subscribed",
        'merge_fields' => $userMergeFields,
    ]);
    \Log::info(varDump($response, ' -1 subscribe $response::'));

It returns structure like :

Array
(
    [id] => 79847477e940c304958adadc24e52312
    [email_address] => [email protected]
    [unique_email_id] => 56ed730de7
    [contact_id] => 7e4dc0052b2bae88c8c914d34e5170d9
    [full_name] => John Doe
    [web_id] => 292542436
    [email_type] => html
    [status] => subscribed
    [consents_to_one_to_one_messaging] => 1
    [sms_phone_number] =>
    [sms_subscription_status] =>
    [sms_subscription_last_updated] =>
    [merge_fields] => stdClass Object

But when I need to unsubscribe user I use method deleteListMember, but it has 2nd parameter subscriber_hash. I tried to pass value of any of the fields id, unique_email_id, contact_id, web_id values from response above

But in all cases I got 404 error :

The requested resource could not be found

Also I searched and did not find any parameter like subscriber_hash under mailchimp user properties :

enter image description here

Searching in net I found some hints that method subscriberHash of mailchimp can be used- but I did not any similar function in the library by packages.

How can I get this subscriberHash value ?

ATTEMPT TO FIX: I modified my code as

$response = $this->getApiClient()->lists->deleteListMember($email, md5(strtolower($email)));

But anyway I got 404 error :

    The requested resource could not be found.

What can be wrong ?

1

There are 1 answers

1
Severin On

You can check their documentation here: https://mailchimp.com/developer/marketing/docs/methods-parameters/#path-parameters

When making a call for information about a particular contact, the Marketing API uses the MD5 hash of the lowercase version of the contact’s email address. We use the MD5 hash because it makes it less likely to leak email addresses—these hashes can’t be translated back to an email address, so if your APIs calls were leaked in some manner, your users’ email addresses remain unexposed.

The subscriber_hash is the clients email, lowercased and MD5 hashed.

So in your Laravel project you can create the hash by doing something like:

md5(strtolower($email));