Integrating Mailchimp APIs in your project

Reading Time: 2 minutes

Mailchimp is an all-in-one marketing platform that helps you manage and talk to your clients, customers, and other interested parties. Our approach to marketing focuses on healthy contact management practices, beautifully designed campaigns, and powerful data analysis. It is a marketing automation platform and email marketing service, used by businesses to manage their mailing lists and create email marketing campaigns and automations to send to customers.

Generate your API key for mailchimp

You can integrate mailchimp in your project by generating a audience id from your mailchimp account. You can refer to the documentation for quick guide.

One you created audience id you are good to go with integration. You can call mailchimp APIs in your project as per requirement.

Note: Mailchimp username and password should be passed as Basic Auth in APIs.

Add user in Audience

Audience is mailchimp list, used to store and manage all of your contacts.

A user can be added using audience id and user email. A unique mailchimp id would be created for user.

POST <- https://us1.api.mailchimp.com/3.0/lists/{{auidenceId}}/members

{
    "email_address": "userToAdd@userDomain.com",
    "status": "subscribed"
}

Send subscribed status to add user in subscribed list. If you want confirmation from user you can send pending status and user will get an email asking for confirmation. Therefore, a unique id would be generated for user once he is added.

Update user details

You can update user details by sending required fields. Below is the example of updating some fields. Checkout this link for more information.

PATCH <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}
{
    "merge_fields": {
        "FNAME": "first name",
        "LNAME": "last name",
        "ADDRESS": "address",
        "PHONE": "phone no."
    }
}

Get User details

You can fetch user details from mailchimp using user id for all the audience list.

GET <- https://us1.api.mailchimp.com/3.0/search-members?query=userEmail@userDomain.com

Get user details from specific audience list

You can fetch user details from a specific audience list using audience id and user’s id.

GET <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}

Add tags in Audience list

Tags are labels you create to help organise your contacts. Tagging lets you bring your own contact structure into Mailchimp and label contacts based on data you know about them. Tags are highly customizable, so you can create and assign them as you see fit.

POST <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}/tags
{
    "tags": [
        {
            "name": {{tagName}},
            "status": "active"
        }
    ]
}

Get user tags from audience

GET <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}/tags

Unsubscribe user from audience

You can unsubsribe a user from an audience list by sending unsubscribed status.

PUT <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}
{
    "status": "unsubscribed"
}

Delete user

You can delete a user from your all audience lists.

POST <- https://us1.api.mailchimp.com/3.0/lists/{{audienceId}}/members/{{userMailchimpId}}/actions/delete-permanent

This is an overview for APIs. You can refer to documentation for more details.

knoldus