Skip to main content

Mailchimp integration

Mailchimp is a web service for creating messaging campaigns, managing mailing lists, adding new customers, and viewing reports.

If you frequently run messaging campaigns to your customers’ email addresses, then you better automate this process using a bot created in the Aimylogic visual editor.

Prepare Mailchimp

  1. Create an account at Mailchimp.

  2. On the bottom-left corner, click the account name and select Account & billing.

    Account & billing

  3. Go to ExtrasAPI keys.

    Extras → API keys

  4. In the Your API keys section, click Create a key. You will get the API key that is used to make requests.

tip
After creating the key, open the Mailchimp documentation.

To run a messaging campaign using the Mailchimp API, you need to make three HTTP requests:

All requests will be made to the main URL: https://<ds>.api.mailchimp.com/3.0/ where <ds> is a unique ID for your account. You can find it in the URL. We will use us3, https://us3.api.mailchimp.com/3.0/.

Prepare a messaging list

To create a messaging campaign, we need to make an address list to send our information to.

  1. In Mailchimp, go to Audiences and click Create Audience. Fill out the required fields, for example:

    Create Audience

  2. Click Save.

  3. Go to AudiencesManage AudienceAdd a subscriber:

    Add a subscriber

  4. Specify user details to whom you plan to send information:

  5. Check This person gave me permission to email them and click Subscribe.

The user is added; if you need to add more users, simply repeat the procedure. If necessary, you can upload an email list to Mailchimp.

Get audience ID

  1. Go to AudiencesManage AudienceSettings:

    Settings

  2. Scroll to the bottom of the page. There will be your audience ID.

    Unique ID for audience

And that’s all you need to do at the Mailchimp side. Now go to the script in Aimylogic.

Set up Aimylogic script

  1. Create the first screen and add a Text block with a hint and the Start Messaging Campaign button.

  2. Create a screen with a Text block and an Intents block and place any text for your mailing campaign.

  3. In the Intents block, use the $TEXT system entity.

    Script sample

Add the first HTTP request

  1. Add the HTTP request to a new screen. This HTTP request will create a mailing campaign. As described in the Mailchimp documentation, you need to make a POST request to a URL that looks like this: https://us3.api.mailchimp.com/3.0/campaign.

    The HTTP request block

    {
    "recipients": {
    "list_id": "Audience ID"
    },
    "type": "regular",
    "settings": {
    "subject_line": "Hints for our service",
    "reply_to": "j.smith@just-ai.com",
    "from_name": "John"
    }
    }
  2. In this HTTP request, go to the Headers tab.

  3. Add the content-type header with the application/json value.

  4. Add the Authorization header with your encoded API key as a value. Use Base64 to encode the key that you obtained in Mailchimp.

    For example, your API key 853abbe21541a9ed7b46a39b004b907qWerTy will look as following: ODUzYWJiZTIxNTQxYTllZDdiNDZhMzliMDA0YjkwN3FXZXJUeQ==

    HTTP request header

  5. In the same HTTP request, go to the Response tab.

  6. To get the ID of the created mailing list, assign $httpResponse.id to the $mailingID variable.

    HTTP request response

Add the second HTTP request

  1. Create new screen with the HTTP request block and connect it with the first HTTP request block. This HTTP request will set the content for the mailing campaign you have just created.

  2. As described in the Mailchimp documentation, you need to make a PUT request to a URL that looks like this: https://us3.api.mailchimp.com/3.0/campaigns/${mailingID}/content. Here mailingID is the variable from the first HTTP request.

  3. In the Body tab, write the following:

    {
    "html": "<p>$TEXT</p>"
    }

    $TEXT is the entity from the previous HTTP request.

    HTTP request body

  4. Add the same headers as in the previous request.

    HTTP request header

Add the third HTTP request

  1. Create new screen with the HTTP request block and connect it with the second HTTP request block. This HTTP request will send your content to the desired mailing list.

  2. As described in the Mailchimp documentation, you need to make a POST request to a URL that looks like this: https://us3.api.mailchimp.com/3.0/campaigns/${mailingID}/actions/send. Here mailingID is the variable from the first HTTP request.

  3. Leave the Body field empty.

  4. Add the same headers as in the previous request.

    HTTP request header

The resulting script looks like this:

Resulting script