Home » PHP22 August 2016

MailChimp API v3.0 – Manage Subscriber using PHP & CURL

This article shows how you can use MailChimp API v3.0 with PHP and CURL to manage MailChimp subscribers. This includes adding subscribers to a list, editing/updating subscribers in a list, adding subscribers to a category/group of a list, fetching and displaying list & list id and groups and groups id as well.

Getting your list ID

The list ID is not the numeric ID of the list. It is a combination of random letter and number.

You will get the list ID from ‘List name and defaults’ page.

– Create a list on your MailChimp account
– Click on that list
– Click on the ‘Settings’ menu
– A dropdown with sub-menus is displayed
– Click on the ‘List name and defaults’ sub-menu.
– On that page, on the right side, you will find the list ID highlighted in red/maroon color.

This link can be helpful to get into the ‘List name and defaults’ page: Find your List ID

Subscribe customer/user to a list

You need an API Key to add subscribers to a mailchimp list. This article shows how you can get an API key on MailChimp: About API Keys.

The API Key is in the format as xxxxxxxxxxxxxxxxxx-us13.

Here,
xxxxxxxxxxxxxxxxxx = some random number and letter
us13 = server name, it can be us2, us3, us10, etc.

The other necessary thing is the list ID to which we will be adding subscribers. Procedure to get List ID is already mentioned above.

Now, let us suppose that we are going to add a subscriber with name Mukesh Chapagain and email as testing123@chapagain.com.np.

Here is the code to do so:

Get Group/Interest Category inside a List

Suppose, you have added a group category / interest category inside a list. The group/interest category can again contain group/interest inside it. So, the depth/hierarchy is like below:

— List
    — Group/Interest Category
        — Group/Interest

The following code will fetch all the group/interest categories present inside a list.

Get Groups/Interests inside a Group/Interest Category

A group/interest category can contain multiple groups/interests. The following code will fetch all the groups/interests present inside a group/interest category.

Add Subscriber to a particular Interest/Group

In the second example above, we added user/customer to a particular list. We then discussed that a list can have interest/group categories and the interest/group category can further have multiple interests/groups associated with it.

The following code shows how to add user/customer to a particular interest/group (it’s not interest/group category but the interest/group present inside the interest/group category). For this, we need interest/group ID. We have seen in the above examples about how to get interest/group id.

– The above code is also used to update subscriber’s information like first name, last name, etc.
– The above code can also be used to add new subscriber.

There is a nice and helpful example on github regarding MailChimp API v3 with PHP & CURL.

Hope this helps. Thanks.

PHP

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.