SDKs overview

Mailchimp provides a suite of Software Development Kits (SDKs) and community-supported libraries designed to facilitate interaction with its marketing platform API. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers to integrate Mailchimp functionalities—such as managing audiences, creating and sending email campaigns, and retrieving analytics—directly into their applications. The official SDKs are maintained by Mailchimp and target widely used programming languages, ensuring compatibility and adherence to the latest API specifications. Community libraries extend this ecosystem, offering support for additional languages or specialized use cases not covered by official offerings.

The Mailchimp API itself is a RESTful interface, enabling programmatic access to various platform features. Developers can manage lists, segments, contacts, campaigns, and reports. The API uses standard HTTP methods (GET, POST, PUT, PATCH, DELETE) and typically returns JSON responses. Authentication for direct API access is primarily handled via API keys, which are unique identifiers generated within the Mailchimp account settings. For applications requiring user authorization without direct API key access, Mailchimp supports OAuth 2.0, allowing third-party applications to access user data with explicit consent from the Mailchimp account owner, as detailed in the Mailchimp OAuth 2.0 guide.

Official SDKs by language

Mailchimp offers official SDKs for several popular programming languages, designed to provide a consistent and supported method for interacting with the Mailchimp API. These SDKs are maintained by Mailchimp and are typically the recommended approach for integrating Mailchimp functionalities into applications. Each SDK provides language-specific wrappers for API endpoints, handling request formatting, response parsing, and error handling.

Language Package Name Installation Command (Example) Maturity
PHP mailchimp/mailchimp-marketing composer require mailchimp/mailchimp-marketing Stable
Python mailchimp_marketing pip install mailchimp_marketing Stable
Ruby mailchimp-marketing gem install mailchimp-marketing Stable
Node.js @mailchimp/mailchimp_marketing npm install @mailchimp/mailchimp_marketing Stable
Java com.mailchimp/mailchimp-marketing Maven: Add dependency to pom.xml; Gradle: Add to build.gradle Stable
Go github.com/mailchimp/mailchimp-marketing-go/v2 go get github.com/mailchimp/mailchimp-marketing-go/v2 Stable

These SDKs are documented within the Mailchimp Developer Reference, offering specific usage examples and API endpoint details for each language. Developers are encouraged to consult these resources for the most up-to-date guidance and best practices.

Installation

Installation of Mailchimp's official SDKs follows standard package management practices for each respective programming language. Below are typical installation instructions for the primary supported languages. An API key and server prefix are required to initialize the SDK clients; the server prefix is specific to the data center where your Mailchimp account resides (e.g., us1, us20, eu1).

PHP

To install the Mailchimp PHP SDK, use Composer:

composer require mailchimp/mailchimp-marketing

Python

Install the Python SDK using pip:

pip install mailchimp_marketing

Node.js

For Node.js projects, use npm or yarn:

npm install @mailchimp/mailchimp_marketing

or

yarn add @mailchimp/mailchimp_marketing

Ruby

Install the Ruby gem:

gem install mailchimp-marketing

Java

For Java projects, you typically add the dependency to your pom.xml (Maven) or build.gradle (Gradle) file. For Maven:

<dependency>
    <groupId>com.mailchimp</groupId>
    <artifactId>mailchimp-marketing</artifactId>
    <version>3.0.80</version> <!-- Use the latest version -->
</dependency>

For Gradle:

implementation 'com.mailchimp:mailchimp-marketing:3.0.80' // Use the latest version

Go

Install the Go module:

go get github.com/mailchimp/mailchimp-marketing-go/v2

Quickstart example

This example demonstrates how to add a new subscriber to a Mailchimp audience using the Python SDK. This involves initializing the client with your API key and server prefix, then calling the appropriate method to interact with the Mailchimp API. The server prefix is the data center associated with your Mailchimp account (e.g., us1, eu1); it can be found at the end of your API key (e.g., YOUR_API_KEY-usX).

Python Example: Add a subscriber

import mailchimp_marketing as MailchimpMarketing
from mailchimp_marketing.api_client import ApiClientError

# Replace with your actual API key and server prefix
api_key = "YOUR_MAILCHIMP_API_KEY"
server_prefix = "YOUR_SERVER_PREFIX" # e.g., "us1", "us20", "eu1"
audience_id = "YOUR_AUDIENCE_ID" # The ID of your Mailchimp audience

client = MailchimpMarketing.Client()
client.set_config({
    "api_key": api_key,
    "server": server_prefix
})

member_info = {
    "email_address": "[email protected]",
    "status": "subscribed",
    "merge_fields": {
        "FNAME": "John",
        "LNAME": "Doe"
    }
}

try:
    response = client.lists.add_list_member(audience_id, member_info)
    print(f"Successfully added contact: {response['id']}")
    print(response)
except ApiClientError as error:
    print(f"Error: {error.text}")

This Python snippet initializes the Mailchimp client, configures it with credentials, and then attempts to add a new member to a specified audience. The status field can be subscribed, unsubscribed, cleaned, or pending. For more detailed examples and advanced operations, refer to the Mailchimp API Campaigns documentation.

Community libraries

Beyond the official SDKs, the Mailchimp developer community has contributed various libraries and wrappers for languages and frameworks not officially supported, or to offer alternative approaches to API interaction. These community-driven projects can be found on platforms like GitHub and often provide solutions for specific use cases or preferences. While not officially maintained or supported by Mailchimp, they can be valuable resources for developers working in environments without official SDKs.

Examples of languages and frameworks that might have community-contributed libraries include:

  • C#/.NET: Several third-party libraries exist on NuGet for integrating Mailchimp with .NET applications.
  • Ruby on Rails: While an official Ruby gem is available, specific Rails-centric gems may offer deeper integration patterns.
  • JavaScript (Browser-side): Libraries designed for front-end applications to interact with Mailchimp via server-side proxies to avoid exposing API keys.
  • Other languages: Developers often create custom wrappers for languages like Scala, Rust, or Elixir to fit their project needs.

When using community libraries, it is important to assess their maintenance status, compatibility with the latest Mailchimp API versions, and community support. Developers should check the project's documentation, issue tracker, and recent commit history to ensure the library is actively maintained and suitable for production use. For example, the Fetch API can be used directly for HTTP requests in browser environments, but requires careful handling of API keys and CORS policies.