Configure MailChimp Webhooks

Video loading...

  • 0:02
    Using MailChimp with Drupal 7
  • 0:04
    Configure MailChimp Webhooks Series Sponsored by MailChimp
  • 0:09
    MailChimp has the ability
  • 0:11
    to trigger a webhook or push notification
  • 0:14
    whenever someone takes an action on their MailChimp account.
  • 0:17
    Like, for example, when someone unsubscribes from your mailing list
  • 0:20
    by clicking the link in their email
  • 0:23
    instead of logging in to their Drupal account
  • 0:25
    and using the checkbox provided there.
  • 0:27
    In this scenario, Drupal can be configured to listen for these webhook notifications
  • 0:31
    and respond whenever they happen.
  • 0:33
    This is particularly useful for allowing Drupal to update cached data
  • 0:37
    about subscribers in real time.
  • 0:39
    In this short tutorial, we'll take a look at how to enable webhooks
  • 0:43
    for your lists in MailChimp, and we'll talk about why this is an important feature to enable.
  • 0:48
    In order for this to work, your site needs to be accessible to the Internet.
  • 0:53
    You won't be able to receive the webhook notifications
  • 0:56
    if your site isn't available to the Internet,
  • 0:59
    so MailChimp won't be able to ping you.
  • 1:01
    It also means you won't be able to configure the webhook
  • 1:04
    because when you attempt to configure the webhook
  • 1:06
    MailChimp will send a test notification
  • 1:09
    to make sure that things work appropriately.
  • 1:11
    I'm also assuming that in this case, you've got a MailChimp list configured already
  • 1:15
    and that Drupal knows about that list
  • 1:18
    through the MailChimp Lists module.
  • 1:21
    If you haven't done that, take a look at our other tutorial in the series
  • 1:23
    about adding lists to MailChimp and synchronizing them in Drupal.
  • 1:27
    By the end of this tutorial, you should be able to configure Drupal
  • 1:30
    to respond to MailChimp webhook notifications.
  • 1:33
    So, I'm using an example site that I've got located on Pantheon
  • 1:38
    for test purposes, in this case,
  • 1:40
    and that allows me to ensure that MailChimp is able to ping my website.
  • 1:45
    With the MailChimp Lists module already enabled,
  • 1:48
    I can go to Configuration,
  • 1:50
    and then MailChimp, under Web Services section,
  • 1:53
    and then click on the Lists tab.
  • 1:55
    It will show me a list of all of the MailChimp lists
  • 1:58
    that I have configured on MailChimp.com.
  • 2:00
    If you don't see your lists here, you can always refresh the cache
  • 2:03
    and get the updated information.
  • 2:05
    Now, in order to enable webhooks,
  • 2:08
    really, all I have to do is click this Enable link,
  • 2:10
    click the confirmation button, and wait for it to complete.
  • 2:14
    You can see here that the webhook has been enabled.
  • 2:17
    This step is only going to work when your Drupal site
  • 2:20
    is accessible to the internet,
  • 2:22
    or if you're using a local tunneling service like ngrok.com, or something,
  • 2:26
    in order to test things out on your local host.
  • 2:29
    Setting up these webhooks is really easy once you've met all the requirements
  • 2:34
    but it is an important step.
  • 2:36
    And the reason for that is that Drupal caches a lot of data
  • 2:38
    from MailChimp about things like a user's subscription
  • 2:42
    or the list itself.
  • 2:44
    You know, if we make changes to our list, we have to hit this button
  • 2:47
    to refresh list data from MailChimp.
  • 2:50
    With webhooks enabled, when a user clicks the unsubscribe link
  • 2:53
    in an email that we sent them and MailChimp unsubscribes them,
  • 2:56
    it will also ping Drupal with a notification of that event.
  • 2:59
    So Drupal can go ahead and update the related Drupal user account
  • 3:03
    and automatically uncheck the subscription box.
  • 3:06
    That way, when the user goes and views their profile,
  • 3:08
    they're not confused and think that they're still subscribed to the list in MailChimp.
  • 3:13
    There's a few other things that these webhooks are used for,
  • 3:15
    caches that are updated in Drupal as well,
  • 3:17
    so it's important to set them up if you get the chance.
  • 3:20
    This caching is in place because it allows Drupal to be more efficient
  • 3:24
    and not make as many requests to the MailChimp API
  • 3:27
    which can be time consuming.
  • 3:29
    Finally, whenever Drupal receives a webhook from MailChimp,
  • 3:34
    it also triggers a hook that modules can implement,
  • 3:37
    documented in the MailChimp.api.php file.
  • 3:41
    So if you ever need to write custom code
  • 3:43
    that responds to actions taken on a user's account in your mailing list,
  • 3:48
    you can implement that hook and do so.
  • 3:51
    In this short tutorial on webhooks,
  • 3:53
    we took a second to configure Drupal's integration
  • 3:56
    with the MailChimp webhooks in order to make sure
  • 3:58
    that Drupal is able to keep cache data up to date
  • 4:02
    whenever a notification is received.

Configure MailChimp Webhooks

Loading...

MailChimp has the ability to trigger a webhook, or push notification, whenever someone takes an action on their MailChimp account. For example, when someone unsubscribes from your mailing list by clicking the link in their email, instead of logging in to their Drupal account and using the checkbox provided there. Drupal, can be configured to listen for these webhook notifications, and take action whenever one is received. This is particularly useful for allowing Drupal to update cached data about subscribers in real time.

If you're using MailChimp with Drupal I highly recommend configuring the webhook integration. It helps to keep the information contained in Drupal and in MailChimp in sync. And, it is super easy to do. In addition, whenever a notice is received, the MailChimp module triggers hook_mailchimp_process_webhook(), documented in mailchimp.api.php. This allows your custom modules to respond to someone subscribing or unsubscribing from your mailing list in any way you want.

In this short tutorial we'll look at how to enable web hooks for your lists in MailChimp, and then talk about why this is an important feature to enable.

In order for the webhook integration to work your Drupal site needs to be accessible to the internet so that it can receive HTTP posts from MailChimp's API.

By the end of this tutorial you should be able to configure Drupal to respond to MailChimp webhook notifications.

Further your learning

  • Why is it important to configure the MailChimp webhooks?
  • Can you give an example of an action that would cause a MailChimp webhook to be triggered?

Series Sponsored by MailChimp

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.