Integration of Mailchimp with Django Rest Framework

In This Modern Era, Email marketing is an important tool to build relationships with customers because it gives freedom to directly communicate with customers.

For successful email marketing, we need to implement some email marketing tools on our website. In this article, I am going to highlight one of an email marketing tool named ‘Mailchimp.’

Mailchimp is a prominent email marketing tool that allows its customers to add email to their subscriber list from websites to use these emails for email campaigns. Mailchimp API provides you to send email to an audience who subscribed to your website. The audiences are also known as Lists.

This blog is going to cover how to set up a Mailchimp account and implementation on the server-side. We will cover the steps in the following order:

  • Setting up a Mailchimp account and creating the API key
  • Create a new audience and generating audience id
  • Installing Mailchimp library for Django
  • Setting up Mailchimp in Django file
  • Create API to add member email to audience

Setting up Mailchimp account:

Here you need to make a Mailchimp Account. It is free of cost. After that, you will navigate to the Dashboard of Mailchimp.

  • Go to the Profile Icon, then click on Account.

  • The page will navigate to the accounts page. Click Extras from the options:
  • From the Dropdown, Click on API keys will navigate to a page to generate your API keys.

  • Copy  the  API keys:

Create a new audience and generating audience id:

  •  Click on the audience icon

  •  From the audience, Section select All Contacts

  • Click on settings
  • From the dropdown, select the Audience name and defaults

  • Copy the Audience ID

  • At Last, you are able to collect Api keys, audience ID, Server details.

Installing Mailchimp library for Django:

  •  First, install the Mailchimp-marketing package:
    pip install Mailchimp-marketing

Adding required values in file for Mailchimp:

  • Go to your project’s settings, and add the following code:
    Project/ Mailchimp credentials
    Mailchimp_API_KEY = "Your API keys here"
    Mailchimp_DATACENTER = 'us7'
    Mailchimp_LIST_ID = "Your list id 
  • The Datacenter is the last three-digit in your API key after the -. e.g:’us7’

Create a view to add email to Mailchimp:

from rest_framework import status
from Mailchimp_marketing import Client
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from Mailchimp_marketing.api_client import ApiClientError
from Mailchimp_integration.settings import (





class MailSubscriptionAPIView(GenericAPIView):

    def subscribe_email(email):


        This function will communicate with Mailchimp api

        to create a member in an audience list


        Mailchimp = Client()


            “api_key”: Mailchimp_API_KEY,

            “server”: Mailchimp_DATA_CENTER


        member_info = {

            “email_address”: email,




            Mailchimp.lists.add_list_member(Mailchimp_LIST_ID, member_info)

        except ApiClientError as error:


    def post(self, request, *args, **kwargs):

        email =[’email’]


        return Response({

                “status_code”: status.HTTP_200_OK,

                “message”“Mail added to Mailchimp”



Create an endpoint for the Class-based view :

from django.urls import path
from .views import MailSubscriptionAPIView
urlpatterns = [

    path(‘subscribe_email’, MailSubscriptionAPIView.as_view(), name‘subscribe-email’ ),




In this way, you can add more emails to your subscriber list and can start an email campaign to boost your Business. Also, you can explore the Mailchimp dashboard to learn more about Mailchimp.



Tech Expert

Nihar is a full stack developer with around 1 year of experience. He is an expert in building python Integrated web applications, creating REST API’s with well designed, testable and efficient code. He is always eager to learn new programming languages and technologies and looking for new ways to optimize the development process.

Get in touch for a detailed discussion.

Hear From Our 100+ Customers

Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.


We had very close go live timeline and MindBowser team got us live a month before.

Shaz Khan
CEO, BuyNow WorldWide

They were a very responsive team! Extremely easy to communicate and work with!

Kristen M.
Founder & CEO, TotTech

We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.

Chacko Thomas
Co-Founder, TEAM8s

Mindbowser is one of the reasons that our app is successful. These guys have been a great team.

Dave Dubier
Founder & CEO, MangoMirror

Mindbowser was very helpful with explaining the development process and started quickly on the project.

Hieu Le
Executive Director of Product Development, Innovation Lab

The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.

Alex Gobel
Co-Founder, Vesica

Mindbowser is professional, efficient and thorough. 

MacKenzie R
Consultant at XPRIZE

Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.

Laurie Mastrogiani
Founder, S.T.A.R.S of Wellness

MindBowser was great; they listened to us a lot and helped us hone in on the actual idea of the app.” “They had put together fantastic wireframes for us.

Bennet Gillogly
Co-Founder, Flat Earth

They're very tech-savvy, yet humble.

Uma Nidmarty
CEO, GS Advisorate, Inc.

Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.

Katie Taylor
Founder, Child Life On Call

As a founder of a budding start-up, it has been a great experience working with Mindbower Inc under Ayush's leadership for our online digital platform design and development activity.

Radhika Kotwal
Founder of Courtyardly

The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!

Michael Wright
Chief Executive Officer, SDOH2Health LLC

They are focused, patient and; they are innovative. Please give them a shot if you are looking for someone to partner with, you can go along with Mindbowser.

David Cain
CEO, thirty2give

We are a small non-profit on a budget and they were able to deliver their work at our prescribed budgets. Their team always met their objectives and I'm very happy with the end result. Thank you, Mindbowser team!!

Bart Mendel
Founder, Mindworks