### Install Mailchimp Python Client with Setuptools Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Install the package using Setuptools. You can install it for the current user or for all users. ```sh python setup.py install --user ``` -------------------------------- ### Install Mailchimp Marketing Python Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/README.md Install the library using pip. This command installs the latest version directly from the GitHub repository. ```bash pip install git+https://github.com/mailchimp/mailchimp-marketing-python.git ``` -------------------------------- ### Examples and Patterns Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/MANIFEST.txt Illustrates common usage patterns and provides code examples for authentication, list management, campaign operations, and error handling. ```APIDOC ## Examples and Patterns This section offers practical code examples and demonstrates common usage patterns for the Mailchimp Marketing Python SDK. ### Authentication Setup - **Basic Auth**: Example of authenticating using an API key. - **OAuth2**: Example of implementing OAuth2 authorization. ### List Management Examples - **Create List**: Code to create a new list. - **Add Members**: Demonstrates adding single or multiple members. - **Batch Operations**: Examples of performing batch add/update operations. ### Campaign Management Examples - **Create Campaign**: Code to create a new campaign. - **Set Content**: Example of defining campaign content. - **Schedule and Send**: Demonstrates scheduling and sending campaigns. - **Retrieve Reports**: Example of fetching campaign performance data. ### Error Handling Patterns - **Retries**: Implementing retry logic for transient errors. - **Safe Member Addition**: Pattern for ensuring members are added or updated safely (upsert). ### Pagination - **Patterns**: Best practices for handling paginated API responses. ``` -------------------------------- ### batches.start Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Starts a new batch request. ```APIDOC ## POST /batches ### Description Starts a new batch request. ### Method POST ### Endpoint /batches ``` -------------------------------- ### connectedSites.verify_script_installation Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Verify the installation of the connected site's script. ```APIDOC ## POST /connected-sites/{connected_site_id}/actions/verify-script-installation ### Description Verify that the tracking script for a connected site has been installed correctly. ### Method POST ### Endpoint /connected-sites/{connected_site_id}/actions/verify-script-installation ### Parameters #### Path Parameters - **connected_site_id** (string) - Required - The ID of the connected site. ``` -------------------------------- ### ecommerce.get_all_store_products Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all products for a specific store. ```APIDOC ## GET /ecommerce/stores/{store_id}/products ### Description Retrieve all products available in a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### Basic Authentication Setup Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Configure the client library to use Basic Authentication with your API key and server prefix. ```APIDOC ## Basic Auth ```python client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) ``` ``` -------------------------------- ### Create an Automation Workflow Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md This example demonstrates how to create a new automation workflow, such as a welcome series, for a specific list. ```APIDOC ## Create an Automation Workflow ### Description Creates a new automation workflow for a given list with specified settings. ### Method client.automations.create ### Parameters - `list_id` (string) - Required - The ID of the list to associate the automation with. - `settings` (object) - Required - Configuration for the automation, including title, from name, and reply-to email. ### Request Example ```python workflow = client.automations.create({ 'type': 'regular', 'list_id': 'abc123', 'settings': { 'title': 'Welcome Series', 'from_name': 'ACME Welcome', 'reply_to': 'welcome@example.com' } }) ``` ### Response #### Success Response - `id` (string) - The unique identifier of the created automation workflow. ``` -------------------------------- ### ecommerce.get_store_product Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific product. ```APIDOC ## GET /ecommerce/stores/{store_id}/products/{product_id} ### Description Retrieve details for a specific product in an e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products/{product_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **product_id** (string) - Required - The ID of the product. ``` -------------------------------- ### ecommerce.get_product_images Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all images for a specific product. ```APIDOC ## GET /ecommerce/stores/{store_id}/products/{product_id}/images ### Description Retrieve all images associated with a specific product. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products/{product_id}/images ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **product_id** (string) - Required - The ID of the product. ``` -------------------------------- ### Import Mailchimp Marketing Package Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Import the mailchimp_marketing package after installation. ```python import mailchimp_marketing ``` -------------------------------- ### Basic Authentication Example Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Demonstrates how to set up basic authentication for the Mailchimp Marketing Python SDK. Ensure your API key is kept secure. ```python from mailchimp_marketing import Client client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) response = client.ping.get() print(response) ``` -------------------------------- ### ecommerce.list_promo_rules Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all promo rules for a specific store. ```APIDOC ## GET /ecommerce/stores/{store_id}/promo-rules ### Description Retrieve all promo rules for a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/promo-rules ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### ecommerce.get_product_variants Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all variants for a specific product. ```APIDOC ## GET /ecommerce/stores/{store_id}/products/{product_id}/variants ### Description Retrieve all variants for a specific product. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products/{product_id}/variants ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **product_id** (string) - Required - The ID of the product. ``` -------------------------------- ### OAuth2 Authentication Setup Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Configure the client library to use OAuth2 authentication with your access token and server prefix. ```APIDOC ## OAuth2 ```python client.set_config({ "access_token": "YOUR_ACCESS_TOKEN", "server": "YOUR_SERVER_PREFIX" }) ``` ``` -------------------------------- ### OAuth2 Authentication Example Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Illustrates setting up OAuth2 authentication for the Mailchimp Marketing Python SDK. This method is suitable for applications requiring user authorization. ```python from mailchimp_marketing import Client client = Client() client.set_config({ "access_token": "YOUR_ACCESS_TOKEN", "server": "YOUR_SERVER_PREFIX" }) response = client.ping.get() print(response) ``` -------------------------------- ### Template Usage Example Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Demonstrates how to use pre-existing or newly created templates for Mailchimp campaigns. This involves referencing template IDs or content. ```python from mailchimp_marketing import Client from mailchimp_marketing.api_client import ApiClientError try: client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) list_id = "YOUR_LIST_ID" template_id = 12345 # Replace with your actual template ID campaign_data = { "type": "regular", "recipients": {"list_id": list_id}, "settings": { "subject_line": "Campaign with Template", "title": "My Template Campaign", "template_id": template_id, "from_name": "My Company", "reply_to": "reply@example.com" } } response = client.campaigns.create_campaign(campaign_data) campaign_id = response['id'] print(f"Campaign created using template ID {template_id}: {campaign_id}") except ApiClientError as error: print(f"An API error occurred: {error.text}") ``` -------------------------------- ### ecommerce.get_promo_rule Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific promo rule. ```APIDOC ## GET /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id} ### Description Retrieve details for a specific promo rule. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **promo_rule_id** (string) - Required - The ID of the promo rule. ``` -------------------------------- ### automations.start_all_emails Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Starts all emails within an automation workflow. ```APIDOC ## POST /automations/{workflow_id}/actions/start-all-emails ### Description Starts all emails within an automation workflow. ### Method POST ### Endpoint /automations/{workflow_id}/actions/start-all-emails ``` -------------------------------- ### ecommerce.stores Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get a list of all e-commerce stores. ```APIDOC ## GET /ecommerce/stores ### Description Retrieve a list of all e-commerce stores associated with your account. ### Method GET ### Endpoint /ecommerce/stores ``` -------------------------------- ### ecommerce.get_product_image Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific product image. ```APIDOC ## GET /ecommerce/stores/{store_id}/products/{product_id}/images/{image_id} ### Description Retrieve details for a specific image of a product. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products/{product_id}/images/{image_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **product_id** (string) - Required - The ID of the product. - **image_id** (string) - Required - The ID of the image. ``` -------------------------------- ### Debug Logging Setup Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Demonstrates how to enable and configure debug logging for the Mailchimp Marketing Python SDK. This is essential for troubleshooting and understanding API interactions. ```python import logging from mailchimp_marketing import Client # Configure logging logging.basicConfig(level=logging.DEBUG) # Initialize client with debug logging enabled try: client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) # Any API call made after this will log detailed information response = client.ping.get() print(response) except Exception as e: print(f"An error occurred: {e}") ``` -------------------------------- ### Add Content to a Campaign Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Set the HTML and plain-text content for a campaign. This example uses Jinja templating for personalization. ```python content = client.campaigns.set_content('campaign123', { 'html': '''
Check out our latest Q3 updates.
Learn More ''', 'text': ''' Welcome, {{FNAME}}! Check out our latest Q3 updates. https://example.com ''' }) print(f"Content added to campaign {campaign['id']}") ``` -------------------------------- ### automations.start_workflow_email Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Starts a specific email within an automation workflow. ```APIDOC ## POST /automations/{workflow_id}/emails/{workflow_email_id}/actions/start ### Description Starts a specific email within an automation workflow. ### Method POST ### Endpoint /automations/{workflow_id}/emails/{workflow_email_id}/actions/start ``` -------------------------------- ### ecommerce.get_promo_codes Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all promo codes for a specific promo rule. ```APIDOC ## GET /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id}/promo-codes ### Description Retrieve all promo codes associated with a specific promo rule. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id}/promo-codes ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **promo_rule_id** (string) - Required - The ID of the promo rule. ``` -------------------------------- ### Get Authentication Settings Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Retrieve a dictionary containing metadata about the configured authentication methods. ```python def auth_settings(self): # ... implementation details ... ``` -------------------------------- ### Example 404 Not Found Error Response Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/06-errors-and-exceptions.md This is an example JSON structure for a 404 Not Found error response from the Mailchimp API. ```json { "type": "http://developer.mailchimp.com/marketing/docs/reference/errors/", "title": "Resource Not Found", "status": 404, "detail": "The requested resource could not be found.", "instance": "550e8400-e29b-41d4-a716-446655440000" } ``` -------------------------------- ### Initialize Configuration Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Create a Configuration object to manage client settings. Initializes with default values for host, API keys, and authentication. ```python Configuration() ``` -------------------------------- ### Example 401 Unauthorized Error Response Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/06-errors-and-exceptions.md This is an example JSON structure for a 401 Unauthorized error response from the Mailchimp API. ```json { "type": "http://developer.mailchimp.com/marketing/docs/reference/errors/", "title": "Authentication Required", "status": 401, "detail": "Your request did not include an API key.", "instance": "550e8400-e29b-41d4-a716-446655440000" } ``` -------------------------------- ### Client Initialization and Configuration Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Shows how to initialize the Mailchimp Marketing Python SDK client with custom configuration options. This includes setting API keys, server details, and other HTTP behaviors. ```python from mailchimp_marketing import Client from mailchimp_marketing.api_client import ApiClientError try: client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) response = client.ping.get() print(response) except ApiClientError as error: print(f"An API error occurred: {error.text}") ``` -------------------------------- ### Get E-commerce Product Activity for Campaign Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/05-additional-apis.md Retrieve e-commerce product activity and revenue data generated from a specific campaign. ```python ecom = client.reports.get_ecommerce_product_activity_for_campaign('abc123') for product in ecom['products']: print(product['title'], product['revenue']) ``` -------------------------------- ### Example 400 Bad Request Error Response Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/06-errors-and-exceptions.md This is an example JSON structure for a 400 Bad Request error response from the Mailchimp API. ```json { "type": "http://developer.mailchimp.com/marketing/docs/reference/errors/", "title": "Invalid Request", "status": 400, "detail": "The requested resource does not exist.", "instance": "550e8400-e29b-41d4-a716-446655440000" } ``` -------------------------------- ### Get Specific Automation Workflow Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/05-additional-apis.md Retrieve details for a specific automation workflow by its ID using the Automations API's get method. ```python workflow = client.automations.get('workflow123') ``` -------------------------------- ### conversations.list Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get a list of conversations. ```APIDOC ## GET /conversations ### Description Retrieve a list of all conversations. ### Method GET ### Endpoint /conversations ``` -------------------------------- ### SDK Entry Points and Initialization Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt This section details how to initialize the Mailchimp Marketing Python SDK, including authentication options and configuration. ```APIDOC ## SDK Initialization and Authentication ### Description This section covers the entry points for the SDK and how to initialize the client, including details on authentication methods and configuration options. ### Authentication Options - Basic Authentication - OAuth2 Authentication ### Configuration Reference - API Key - Server Prefix - Timeout settings - Proxy settings ### Code Example (Initialization) ```python from mailchimp_marketing import Client client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) ``` ``` -------------------------------- ### Create a Campaign Using a Template Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md This code demonstrates how to create a regular campaign and then set its content using a previously created template. Ensure 'template_id_here' is replaced with the actual ID of your template. ```python # Create campaign using template campaign = client.campaigns.create({ 'type': 'regular', 'recipients': {'list_id': 'abc123'}, 'settings': { 'title': 'Newsletter using Template', 'subject_line': 'Our Latest Updates', 'from_name': 'ACME', 'reply_to': 'reply@example.com', 'template_id': 'template_id_here' } }) # Set the template variables content = client.campaigns.set_content('campaign123', { 'template': { 'id': 'template_id_here', 'sections': { 'HEADER_TITLE': 'Q3 Newsletter', 'BODY_TEXT': 'Check out our latest announcements', 'CTA_URL': 'https://example.com/news', 'CTA_BUTTON_TEXT': 'Read More' } } }) ``` -------------------------------- ### Create a New List Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Provides a code example for creating a new audience list in Mailchimp. This includes setting up essential contact and campaign default information. ```APIDOC ## Create a New List ### Description This example shows how to create a new audience list. It requires details such as the list name, contact information, permission reminder, and default campaign settings. ### Method ```python client.lists.create_list(data) ``` ### Request Body - **name** (string) - Required - The name of the list. - **contact** (object) - Required - Contact information for the list. - **company** (string) - Required - Company name. - **address1** (string) - Required - Street address. - **address2** (string) - Optional - Address line 2. - **city** (string) - Required - City. - **state** (string) - Required - State or province. - **zip** (string) - Required - Postal or ZIP code. - **country** (string) - Required - Country code. - **phone** (string) - Optional - Phone number. - **permission_reminder** (string) - Required - The text that will be shown in the footer of emails. - **campaign_defaults** (object) - Required - Default settings for campaigns. - **from_name** (string) - Required - Default "From" name for campaigns. - **from_email** (string) - Required - Default "From" email address for campaigns. - **subject** (string) - Required - Default subject line for campaigns. - **language** (string) - Required - Default language for campaigns. - **email_type_option** (boolean) - Optional - Whether to use the double opt-in confirmation message. - **visibility** (string) - Optional - The visibility of the list ('pub' or 'prv'). ### Request Example ```python # Create an audience list new_list = client.lists.create_list({ 'name': 'Q3 Newsletter Subscribers', 'contact': { 'company': 'ACME Inc', 'address1': '123 Main Street', 'address2': 'Suite 100', 'city': 'Springfield', 'state': 'IL', 'zip': '62701', 'country': 'US', 'phone': '217-555-0100' }, 'permission_reminder': 'You subscribed to receive our quarterly newsletter', 'campaign_defaults': { 'from_name': 'ACME Marketing', 'from_email': 'marketing@example.com', 'subject': 'Latest News from ACME', 'language': 'en' }, 'email_type_option': True, 'visibility': 'pub' }) print(f"List created: {new_list['id']}") print(f"List name: {new_list['name']}") ``` ### Response #### Success Response (200) - **id** (string) - The unique ID of the created list. - **name** (string) - The name of the created list. ``` -------------------------------- ### Client and Configuration Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/MANIFEST.txt Documentation for the Client class, ApiClient, and Configuration class, including constructor, configuration options, and HTTP operations. ```APIDOC ## Client and Configuration This section details the `Client` class constructor and its configuration, the `ApiClient` for HTTP operations, and the `Configuration` class for advanced setup. ### Client Class - **Constructor**: Initializes the Mailchimp client. - **Configuration**: Options for setting up the client, including authentication and API endpoints. ### ApiClient Class - **HTTP Operations**: Handles all direct HTTP requests to the Mailchimp API. - **Error Handling**: Utilizes `ApiClientError` for managing API-related exceptions. ### Configuration Class - **Advanced Setup**: Provides options for fine-tuning client behavior, such as custom HTTP clients or retry strategies. ``` -------------------------------- ### ecommerce.get_order Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific order. ```APIDOC ## GET /ecommerce/stores/{store_id}/orders/{order_id} ### Description Retrieve details for a specific order from an e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/orders/{order_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **order_id** (string) - Required - The ID of the order. ``` -------------------------------- ### List Creation and Management Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Provides examples for creating and managing audiences (lists) within Mailchimp using the Python SDK. This covers basic CRUD operations for lists. ```python from mailchimp_marketing import Client from mailchimp_marketing.api_client import ApiClientError try: client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) # Create a new list list_data = { "name": "My Awesome List", "contact": { "company": "My Company", "address1": "123 Main St", "city": "Anytown", "state": "CA", "zip": "12345", "country": "US" }, "permission_reminder": "You're receiving this email because you opted in.", "use_archive_bar": True } response = client.lists.create_list(list_data) print(f"List created: {response}") # Get all lists response = client.lists.get_all_lists() print(f"All lists: {response}") except ApiClientError as error: print(f"An API error occurred: {error.text}") ``` -------------------------------- ### ecommerce.get_store_orders Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all orders for a specific store. ```APIDOC ## GET /ecommerce/stores/{store_id}/orders ### Description Retrieve all orders for a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/orders ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### Client and Configuration API Reference Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/README.md Reference for the main SDK entry point and low-level HTTP client, including configuration and error handling. ```APIDOC ## Client Class ### Description The main entry point for the SDK. It allows for initialization with optional configuration. ### Methods - **Constructor**: Initializes the client, accepting an optional configuration object. - **`set_config(config)`**: Updates the client's configuration. ## ApiClient Class ### Description A low-level HTTP client responsible for making API requests. ### Methods - **`call_api(resource_path, method, query_params, post_data, header_params, body, auth_settings)`**: Executes HTTP requests. - **`request(method, url, query_params, post_data, header_params, body, auth_settings)`**: Makes HTTP calls with authentication. - **`sanitize_for_serialization(obj)`**: Converts objects into a JSON-serializable format. ## ApiClientError Exception ### Description Represents errors encountered during API client operations. ### Attributes - **`status`**: The HTTP status code of the error. - **`reason`**: The reason phrase for the HTTP status. - **`body`**: The response body associated with the error. ## Configuration Class ### Description Handles advanced configuration options for the API client. ### Methods - **Constructor**: Initializes configuration with various settings. - **`auth_settings()`**: Retrieves authentication settings. - **`debug_report()`**: Provides a debug report of the configuration. ``` -------------------------------- ### ecommerce.get_store_customer Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific customer. ```APIDOC ## GET /ecommerce/stores/{store_id}/customers/{customer_id} ### Description Retrieve details for a specific customer in an e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/customers/{customer_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **customer_id** (string) - Required - The ID of the customer. ``` -------------------------------- ### ecommerce.get_all_store_customers Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all customers for a specific store. ```APIDOC ## GET /ecommerce/stores/{store_id}/customers ### Description Retrieve all customers associated with a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/customers ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### Instantiate ApiClient with API Key Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Create an instance of the `ApiClient` using an API key and server prefix. Ensure you replace 'YOUR_API_KEY' with your actual Mailchimp API key. ```python from mailchimp_marketing.api_client import ApiClient api_client = ApiClient({"api_key": "YOUR_API_KEY", "server": "us19"}) ``` -------------------------------- ### Get API Key with Prefix Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Retrieve an API key, optionally including its prefix (e.g., 'Bearer'). Useful for constructing authorization headers. ```python def get_api_key_with_prefix(self, identifier): # ... implementation details ... ``` -------------------------------- ### Client Class Constructor Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Initializes the Mailchimp Marketing client. It can be configured with authentication and request settings. ```APIDOC ## Client Class Constructor ### Description Initializes the `Client` class, which is the main entry point for all SDK operations. It initializes an `ApiClient` and exposes all API resource classes as attributes. ### Signature ```python Client(config={}) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `config` | dict | No | `{}` | Configuration dictionary with authentication and request settings | ### Returns Client instance with initialized API resources ### Throws None directly, but `set_config()` may raise `ApiClientError` if authentication fails on first use. ### Example ```python import mailchimp_marketing # Initialize with no config client = mailchimp_marketing.Client() # Or initialize with config client = mailchimp_marketing.Client({ "api_key": "YOUR_API_KEY", "server": "us19" }) ``` ``` -------------------------------- ### conversations.get_conversation_messages Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all messages for a specific conversation. ```APIDOC ## GET /conversations/{conversation_id}/messages ### Description Retrieve all messages within a specific conversation. ### Method GET ### Endpoint /conversations/{conversation_id}/messages ### Parameters #### Path Parameters - **conversation_id** (string) - Required - The unique ID of the conversation. ``` -------------------------------- ### Basic Authentication with API Key Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Demonstrates how to initialize the Mailchimp client and configure it using an API key for authentication. It also includes a verification step using the ping endpoint. ```APIDOC ## Basic Authentication with API Key ### Description This example shows how to set up basic authentication using an API key. It initializes the client, configures it with the API key and server, and then verifies the connection by pinging the API. ### Method ```python client.set_config() client.ping.get() ``` ### Request Example ```python import mailchimp_marketing from mailchimp_marketing.api_client import ApiClientError # Initialize client client = mailchimp_marketing.Client() # Configure with API key client.set_config({ 'api_key': 'YOUR_API_KEY', 'server': 'us19' # Extract from api_key: format is {key}-{server} }) # Verify credentials with ping try: response = client.ping.get() print("✓ Authentication successful") except ApiClientError as e: print(f"✗ Authentication failed: {e.text}") ``` ### Response #### Success Response (200) - **response** (object) - A success message indicating authentication is valid. ``` -------------------------------- ### conversations.get Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific conversation. ```APIDOC ## GET /conversations/{conversation_id} ### Description Retrieve details for a specific conversation. ### Method GET ### Endpoint /conversations/{conversation_id} ### Parameters #### Path Parameters - **conversation_id** (string) - Required - The unique ID of the conversation. ``` -------------------------------- ### connectedSites.list Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get a list of all connected sites. ```APIDOC ## GET /connected-sites ### Description Retrieve a list of all sites connected to your Mailchimp account. ### Method GET ### Endpoint /connected-sites ``` -------------------------------- ### Quick Start: Initialize and Ping Mailchimp API Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Initialize the Mailchimp client, set your API key and server prefix, and make a ping request to verify the connection. Handles potential API errors. ```python import mailchimp_marketing as MailchimpMarketing from mailchimp_marketing.api_client import ApiClientError try: client = MailchimpMarketing.Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) response = client.ping.get() print(response) except ApiClientError as error: print(error) ``` -------------------------------- ### templateFolders.create Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Creates a new template folder. ```APIDOC ## POST /template-folders ### Description Creates a new template folder. ### Method POST ### Endpoint /template-folders ``` -------------------------------- ### ecommerce.get_promo_code Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific promo code. ```APIDOC ## GET /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id}/promo-codes/{promo_code_id} ### Description Retrieve details for a specific promo code. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/promo-rules/{promo_rule_id}/promo-codes/{promo_code_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **promo_rule_id** (string) - Required - The ID of the promo rule. - **promo_code_id** (string) - Required - The ID of the promo code. ``` -------------------------------- ### Basic Authentication with API Key Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Initialize the Mailchimp client and configure it using an API key and server prefix. Verifies authentication by pinging the API. ```python import mailchimp_marketing from mailchimp_marketing.api_client import ApiClientError # Initialize client client = mailchimp_marketing.Client() # Configure with API key client.set_config({ 'api_key': 'YOUR_API_KEY', 'server': 'us19' # Extract from api_key: format is {key}-{server} }) # Verify credentials with ping try: response = client.ping.get() print("✓ Authentication successful") except ApiClientError as e: print(f"✗ Authentication failed: {e.text}") ``` -------------------------------- ### ecommerce.get_product_variant Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific product variant. ```APIDOC ## GET /ecommerce/stores/{store_id}/products/{product_id}/variants/{variant_id} ### Description Retrieve details for a specific variant of a product. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/products/{product_id}/variants/{variant_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **product_id** (string) - Required - The ID of the product. - **variant_id** (string) - Required - The ID of the variant. ``` -------------------------------- ### Campaign Creation and Sending Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/FILES.txt Provides examples for creating, configuring, and sending email campaigns using the Mailchimp Marketing Python SDK. This covers setting up content, scheduling, and sending options. ```python from mailchimp_marketing import Client from mailchimp_marketing.api_client import ApiClientError try: client = Client() client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" }) list_id = "YOUR_LIST_ID" # Create a campaign campaign_data = { "type": "regular", "recipients": {"list_id": list_id}, "settings": { "subject_line": "Test Campaign", "title": "My Test Campaign", "from_name": "My Company", "reply_to": "reply@example.com" } } response = client.campaigns.create_campaign(campaign_data) campaign_id = response['id'] print(f"Campaign created with ID: {campaign_id}") # Set campaign content content_data = { "html": "This is a test campaign.
" } response = client.campaigns.set_campaign_content(campaign_id, content_data) print(f"Campaign content set: {response}") # Send the campaign response = client.campaigns.send_campaign(campaign_id) print(f"Campaign sent: {response}") except ApiClientError as error: print(f"An API error occurred: {error.text}") ``` -------------------------------- ### campaignFolders.create Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Creates a new campaign folder. ```APIDOC ## POST /campaign-folders ### Description Creates a new campaign folder. ### Method POST ### Endpoint /campaign-folders ``` -------------------------------- ### ecommerce.get_all_order_line_items Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all line items for a specific order. ```APIDOC ## GET /ecommerce/stores/{store_id}/orders/{order_id}/lines ### Description Retrieve all line items associated with a specific order. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/orders/{order_id}/lines ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **order_id** (string) - Required - The ID of the order. ``` -------------------------------- ### ecommerce.get_store_cart Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific shopping cart. ```APIDOC ## GET /ecommerce/stores/{store_id}/carts/{cart_id} ### Description Retrieve details for a specific shopping cart. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/carts/{cart_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **cart_id** (string) - Required - The ID of the cart. ``` -------------------------------- ### batchWebhooks.create Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Creates a new batch webhook. ```APIDOC ## POST /batch-webhooks ### Description Creates a new batch webhook. ### Method POST ### Endpoint /batch-webhooks ``` -------------------------------- ### Initialize Mailchimp Marketing Client Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Instantiate the Client class to begin interacting with the Mailchimp API. You can initialize it with default settings or provide a configuration dictionary. ```python import mailchimp_marketing # Initialize with no config client = mailchimp_marketing.Client() # Or initialize with config client = mailchimp_marketing.Client({ "api_key": "YOUR_API_KEY", "server": "us19" }) ``` -------------------------------- ### ecommerce.get_store_carts Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all shopping carts for a specific store. ```APIDOC ## GET /ecommerce/stores/{store_id}/carts ### Description Retrieve all shopping carts for a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/carts ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### ecommerce.get_store Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific e-commerce store. ```APIDOC ## GET /ecommerce/stores/{store_id} ### Description Retrieve details for a specific e-commerce store. ### Method GET ### Endpoint /ecommerce/stores/{store_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. ``` -------------------------------- ### Basic Mailchimp API Usage Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/README.md Demonstrates how to initialize the client, configure authentication, verify the connection, retrieve all lists, and add a new member to a list. Replace 'YOUR_API_KEY' and 'us19' with your actual Mailchimp API key and server prefix. ```python import mailchimp_marketing from mailchimp_marketing.api_client import ApiClientError # Create client client = mailchimp_marketing.Client() # Configure authentication client.set_config({ 'api_key': 'YOUR_API_KEY', 'server': 'us19' }) # Verify connection try: response = client.ping.get() print("✓ Connected to Mailchimp") except ApiClientError as error: print(f"✗ Error: {error.text}") # Get all lists lists = client.lists.get_all_lists() for list_obj in lists['lists']: print(f"- {list_obj['name']} ({list_obj['stats']['member_count']} subscribers)") # Add a member member = client.lists.add_list_member('abc123', { 'email_address': 'john@example.com', 'status': 'subscribed', 'merge_fields': {'FNAME': 'John'} }) print(f"Member added: {member['id']}") ``` -------------------------------- ### ApiClient Constructor Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Initializes the ApiClient with a configuration dictionary. This client handles HTTP requests, authentication, and error handling. ```APIDOC ## ApiClient Constructor ### Description Initializes the ApiClient with a configuration dictionary. This client handles HTTP requests, authentication, and error handling. ### Signature ```python ApiClient(config={}) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters | Parameter | Type | Description | |-----------|------|-------------| | `config` | dict | Configuration dictionary | ### Attributes - `host` (str) — Base API URL, defaults to `https://server.api.mailchimp.com/3.0` - `default_headers` (dict) — Default HTTP headers sent with all requests - `api_key` (str) — Basic auth API key - `access_token` (str) — OAuth2 bearer token - `server` (str) — Server prefix extracted from api_key or explicitly set - `timeout` (int) — Request timeout in seconds - `is_basic_auth` (bool) — True if api_key is configured - `is_oauth` (bool) — True if access_token is configured ### Example ```python from mailchimp_marketing.api_client import ApiClient api_client = ApiClient({"api_key": "YOUR_API_KEY", "server": "us19"}) ``` ``` -------------------------------- ### ecommerce.orders Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get a list of all orders across all stores. ```APIDOC ## GET /ecommerce/orders ### Description Retrieve a list of all orders from all e-commerce stores. ### Method GET ### Endpoint /ecommerce/orders ``` -------------------------------- ### conversations.get_conversation_message Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get a specific message within a conversation. ```APIDOC ## GET /conversations/{conversation_id}/messages/{message_id} ### Description Retrieve a specific message from a conversation. ### Method GET ### Endpoint /conversations/{conversation_id}/messages/{message_id} ### Parameters #### Path Parameters - **conversation_id** (string) - Required - The unique ID of the conversation. - **message_id** (string) - Required - The unique ID of the message. ``` -------------------------------- ### Configure Client with API Key Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/01-overview.md Use this method to configure the client with your Mailchimp API key and server prefix for basic authentication. ```python client.set_config({ "api_key": "YOUR_API_KEY", "server": "YOUR_SERVER_PREFIX" # e.g., "us19" }) ``` -------------------------------- ### Configure Client with OAuth2 Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/01-overview.md Use this method to configure the client with an OAuth2 access token and server prefix for alternative authentication. ```python client.set_config({ "access_token": "YOUR_ACCESS_TOKEN", "server": "YOUR_SERVER_PREFIX" }) ``` -------------------------------- ### connectedSites.get Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific connected site. ```APIDOC ## GET /connected-sites/{connected_site_id} ### Description Retrieve details for a specific connected site. ### Method GET ### Endpoint /connected-sites/{connected_site_id} ### Parameters #### Path Parameters - **connected_site_id** (string) - Required - The ID of the connected site. ``` -------------------------------- ### Create an E-commerce Store Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Set up a new store for e-commerce tracking within Mailchimp. You need to provide a unique store ID, list ID, name, domain, and contact information. ```python # Set up a store for e-commerce tracking store = client.ecommerce.add_store({ 'id': 'my_shopify_store', 'list_id': 'abc123', 'name': 'ACME Online Store', 'domain': 'acme-store.myshopify.com', 'email_address': 'store@example.com', 'currency_code': 'USD', 'primary_locale': 'en_US', 'timezone': 'America/Chicago' }) print(f"Store created: {store['id']}") ``` -------------------------------- ### campaigns.create Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Creates a new campaign. ```APIDOC ## POST /campaigns ### Description Creates a new campaign. ### Method POST ### Endpoint /campaigns ``` -------------------------------- ### ecommerce.get_order_line_item Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific line item in an order. ```APIDOC ## GET /ecommerce/stores/{store_id}/orders/{order_id}/lines/{line_id} ### Description Retrieve details for a specific line item within an order. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/orders/{order_id}/lines/{line_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **order_id** (string) - Required - The ID of the order. - **line_id** (string) - Required - The ID of the line item. ``` -------------------------------- ### ecommerce.get_cart_line_item Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get details for a specific line item in a cart. ```APIDOC ## GET /ecommerce/stores/{store_id}/carts/{cart_id}/lines/{line_id} ### Description Retrieve details for a specific line item within a shopping cart. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/carts/{cart_id}/lines/{line_id} ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **cart_id** (string) - Required - The ID of the cart. - **line_id** (string) - Required - The ID of the line item. ``` -------------------------------- ### landingPages.create Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Creates a new landing page. ```APIDOC ## POST /landing-pages ### Description Creates a new landing page. ### Method POST ### Endpoint /landing-pages ``` -------------------------------- ### Send a Test Email for Campaign Preview Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/07-examples-and-patterns.md Send a test version of the campaign to specified email addresses for previewing. Supports sending HTML, text, or both. ```python client.campaigns.send_test_email('campaign123', { 'test_emails': ['your-email@example.com'], 'send_type': 'all' # html, text, or all }) print("Test email sent to your inbox") ``` -------------------------------- ### ecommerce.get_all_cart_line_items Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Get all line items for a specific shopping cart. ```APIDOC ## GET /ecommerce/stores/{store_id}/carts/{cart_id}/lines ### Description Retrieve all line items within a specific shopping cart. ### Method GET ### Endpoint /ecommerce/stores/{store_id}/carts/{cart_id}/lines ### Parameters #### Path Parameters - **store_id** (string) - Required - The ID of the store. - **cart_id** (string) - Required - The ID of the cart. ``` -------------------------------- ### batchWebhooks.list Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Lists all batch webhooks. ```APIDOC ## GET /batch-webhooks ### Description Lists all batch webhooks. ### Method GET ### Endpoint /batch-webhooks ``` -------------------------------- ### Unschedule Campaign Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/04-campaigns-api.md Cancel a scheduled campaign before it has started sending. ```APIDOC ## unschedule(campaign_id, **kwargs) ### Description Cancel a scheduled campaign (can only be done before sending starts). ### Method POST (Implied by SDK method) ### Endpoint /campaigns/{campaign_id}/actions/unschedule ### Parameters #### Path Parameters - **campaign_id** (str) - Required - Campaign identifier ### Response #### Success Response (200) - **id** (str) - The campaign ID. - **status** (str) - The current status of the campaign. ### Response Example ```json { "id": "abc123", "status": "unscheduled" } ``` ``` -------------------------------- ### ecommerce.add_store_product Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/README.md Adds a new product to an e-commerce store. ```APIDOC ## POST /ecommerce/stores/{store_id}/products ### Description Adds a new product to a specified e-commerce store. ### Method POST ### Endpoint /ecommerce/stores/{store_id}/products ``` -------------------------------- ### Generate Debug Report Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/02-client-and-configuration.md Create a multi-line string report with system information, including OS, Python version, and SDK details. ```python def to_debug_report(self): # ... implementation details ... ``` -------------------------------- ### Get Template Source: https://github.com/mailchimp/mailchimp-marketing-python/blob/master/_autodocs/05-additional-apis.md Retrieves the details of a specific email template by its ID. ```APIDOC ## get_template ### Description Get a specific template by its ID. ### Method `client.templates.get_template(template_id, **kwargs)` ### Parameters #### Path Parameters - `template_id` (str) - Required - Template ID ### Returns Template object ### Request Example ```python template = client.templates.get_template('tpl123') ``` ```