Mailchimp Marketing Node.js Client

repository·master·Indexed 41 days ago

https://github.com/mailchimp/mailchimp-marketing-node

The official Node.js client library for the Mailchimp Marketing API (version 3.0.80), providing a programmatic interface to manage campaigns, automation workflows, batch requests, and campaign folders.

Tokens
27.6K
Snippets
182
Records
183
Agent score
51%

What's inside Mailchimp

  1. Configure authentication using OAuth2

    master

    To use OAuth2 authentication, call mailchimp.setConfig() and provide your accessToken and the server prefix (e.g., us19). The server prefix is required so the client can determine the appropriate host URL.

    mailchimp.setConfig({
      accessToken: 'YOUR_ACCESS_TOKEN',
      server: 'YOUR_SERVER_PREFIX',
    });
  2. Configure authentication using Basic Auth

    master

    To use Basic Authentication, call mailchimp.setConfig() and provide your apiKey and the server prefix (e.g., us19). The server prefix is required so the client can determine the appropriate host URL.

    mailchimp.setConfig({
      apiKey: 'YOUR_API_KEY',
      server: 'YOUR_SERVER_PREFIX',
    });
  3. Quick Start with Mailchimp Marketing Node.js

    master

    To get started, import the library, configure it with your API key and server prefix using setConfig, and then call API methods. The following example demonstrates how to use the ping.get() method to verify connectivity.

    const mailchimp = require('@mailchimp/mailchimp_marketing');
    
    mailchimp.setConfig({
      apiKey: 'YOUR_API_KEY',
      server: 'YOUR_SERVER_PREFIX',
    });
    
    async function callPing() {
      const response = await mailchimp.ping.get();
      console.log(response);
    }
    
    callPing();
  4. List member information

    master

    Retrieve information about members in a specific Mailchimp list. You can filter by status, email type, interests, and timeframes. Use getListMembersInfo for the data or getListMembersInfoWithHttpInfo for the full response.

    // Returns the data of type ListMembers2
    const members = await listsApi.getListMembersInfo(listId, {
      count: 10,
      offset: 0,
      status: 'subscribed',
      interestCategoryId: 'category_id',
      interestIds: 'id1,id2',
      interestMatch: 'any'
    });
  5. Batch subscribe or unsubscribe list members

    master

    Use batchListMembers to perform bulk subscription or unsubscription operations for members within a specific list.

    Options:

    • skipMergeValidation (Boolean): If true, member data is accepted without merge field values, even if the field is usually required. Defaults to false.
    • skipDuplicateCheck (Boolean): If true, duplicates in the request are ignored; the status of the first appearance is saved. Defaults to false.
    // listId: The unique ID for the list.
    // body: An object of type MembersToSubscribeUnsubscribeTofromAListInBatch
    // opts: { skipMergeValidation?: boolean, skipDuplicateCheck?: boolean }
    await listsApi.batchListMembers(listId, body, opts);
  6. Manage Ecommerce Orders and Line Items

    master

    Handle order processing by creating new orders and adding line items to them within a store.

    // Add a new order to a store
    const order = await ecommerceApi.addStoreOrder(storeId, {
      // body follows EcommerceOrder1 schema
    });
    
    // Add a line item to an existing order
    const orderLineItem = await ecommerceApi.addOrderLineItem(storeId, orderId, {
      // body follows EcommerceOrderLineItem3 schema
    });
  7. Get a specific interest in a category

    master

    Retrieve details for a specific interest or 'group name' within a category. Use getInterestCategoryInterest for the data or getInterestCategoryInterestWithHttpInfo for the full response.

    // Returns the data of type Interest
    const interest = await listsApi.getInterestCategoryInterest(listId, interestCategoryId, interestId);
  8. Get list member goal events

    master

    Retrieve the last 50 Goal events for a specific member on a list. The subscriberHash can be the MD5 hash of the lowercase version of the member's email address, the email address itself, or the contact_id.

    // Returns a Promise with the CollectionOfMemberActivityEvents data
    const goals = await listsApi.getListMemberGoals(listId, subscriberHash, {
      fields: ['event_type', 'timestamp'],
      excludeFields: ['internal_id']
    });
  9. List campaign folders

    master

    Retrieve all folders used to organize campaigns. You can use pagination via count and offset, and filter returned fields using fields and excludeFields.

    /**
     * @param {Object} opts
     * @param {Array.<String>} opts.fields - A comma-separated list of fields to return.
     * @param {Array.<String>} opts.excludeFields - A comma-separated list of fields to exclude.
     * @param {Number} opts.count - Number of records to return (Default: 10, Max: 1000).
     * @param {Number} opts.offset - Number of records to skip for pagination (Default: 0).
     */
    const folders = await campaignFoldersApi.list(opts);