Mailchimp Webhooks

#Overview

You can use webhooks in Mailchimp to send data back to your WordPress site using WP Fusion. Using these webhooks, you can create new users on your WordPress site, or update existing users’ meta data and tags.

Having trouble receiving webhooks? Check out our troubleshooting guide.

There are two ways to configure webhooks in Mailchimp, either globally to your account (available on all plans), or using the journey builder (available with the Standard plan and higher).

#Global webhooks

Global webhooks are managed in Mailchimp by going to your list and clicking Settings » Webhooks.

For this tutorial, we’ll be showing you how to create a new WordPress user when a contact is added to your Mailchimp list. See below for additional options when constructing the URL parameters.

First, click Create New Webhook. Then enter the URL to your WordPress site, including ?wpf_action=add and your access key, like in the screenshot below.

For the triggers we’ve selected “Subscribes” and “Profile Updates”.

Now, every time a subscriber joins this list, a new WordPress user will be created based on their contact data in Mailchimp. If the user already exists on the site, they will be updated (no duplicate users will be created).

Since we’ve enabled “Profile Updates”, the user in WordPress will also be updated whenever their profile is modified within Mailchimp.

Note: The Profile Updates trigger will only send a webhook when a subscriber’s fields have been edited, not their tags. To sync tag changes back to WordPress, you will need to create a webhook in a Journey.

#Webhooks in journeys

With a Mailchimp Standard plan or higher, you can add webhooks to journeys. This gives you more control over the webhook targeting.

For example you can:

  • Import a WordPress user only when a specific tag is applied.
  • Only import WordPress users after free trial customers have reached the end of their trial.
  • Trigger an update of a WordPress user’s cached tags when a tag is applied in Mailchimp.

First, create a journey, and select your trigger. In this case we are using a Tag Applied trigger.

For the next step, add a Webhook action.

Configure the webhook like so:

  • Webhook name: Pick any name that will help you remember what the webhook does.
  • URL destination: Enter the webhook URL to your site, following the examples below. You can also copy/paste your webhook URL out of the Webhooks section on the General tab in the WP Fusion settings.
  • Authentication: None.
  • Headers: None.
  • Content: copy and paste the code below into the Payload field:
{
  "contact_id": "*|EMAIL|*"
}

Finally, save and publish your journey.

Now when the selected tag is applied in Mailchimp, a user will automatically be imported in WordPress.

#Webhook URL methods

WP Fusion supports several URL methods for webhooks:

#To update a user’s tags

To update an existing WordPress user’s tags from the contact record, the URL for the webhook should look like the following:

https://mydomain.com/?wpf_action=update_tags&access_key=YOURACCESSKEY

#To update a user’s tags and meta data

To update a user’s tags and pull any new meta data from Mailchimp for that contact, the URL for the webhook should look like the following:

https://mydomain.com/?wpf_action=update&access_key=YOURACCESSKEY

#Create a new user

To create a new user, use the following URL:

https://mydomain.com/?wpf_action=add&access_key=YOURACCESSKEY

You can also specify additional parameters in user creation. For example, to send the user a welcome email containing a link to log in on your site, use the following:

https://mydomain.com/?wpf_action=add&access_key=YOURACCESSKEY&send_notification=true

You can also specify a specific user role to be assigned to the new user. For example, to set the new user to the “customer” role, use the following:

https://mydomain.com/?wpf_action=add&access_key=YOURACCESSKEY&role=customer

Note that you have to have registered a “customer” role on your site for this to work. By default users will be assigned the role of “subscriber”.

The add method will update a user if an existing user already exists. It will not create a duplicate user.

Note: By default, user accounts will be created with their email address as the username and a randomly generated password. However, if you have created a custom username field and password field in Mailchimp, and enabled these fields in WP Fusion for sync with user_login and user_pass on your website, the new users will be given the usernames and passwords stored in their Mailchimp contact record.

#User passwords

New user accounts will be created with an automatically generated password. If you’d like to use this password in your email marketing, you can send the password back to Mailchimp after it has been generated.

In the Webhooks section of the General settings tab, check the box for Return Password, and select a field in Mailchimp where the password should be stored.

After a new user is created, their automatically generated password will now be saved back to their contact record, and you can use a merge field to include it in an email. The username will be the contact’s email address.

Was this helpful?