How to send email using MailChimp API

13,685

Solution 1

There is no "SendEmail" endpoint in API v3.0. MailChimp's STS was a pre-cursor to its Mandrill transactional service and may only still work for user accounts that have existing STS campaigns. No new STS campaigns can be created. If you have a monthly, paid MailChimp account, you should look into Mandrill. If not, I've had good luck with Mailgun.

Solution 2

You should use HTTP Basic authentication in MailChimp API 3.0.

needle.get('https://<dc>.api.mailchimp.com/3.0/<endpoint>', { username: 'anystring', password: 'your_apikey' },
  function(err, resp) {
      // your code here...
});

EDIT

@TooMuchPete is right, the SendMail endpoint is not valid in MailChimp API v3.0. I didn't notice that and I've edited my answer.

Share:
13,685

Related videos on Youtube

Tay Moore
Author by

Tay Moore

Updated on September 05, 2022

Comments

  • Tay Moore
    Tay Moore over 1 year

    I'm creating an app in nodejs to send an email using MailChimp. I've tried to use https://apidocs.mailchimp.com/sts/1.0/sendemail.func.php but changed it to use 3.0 api because 1.0 seems to no longer work (big surprise). I've setup my app with

    var apiKey = '<<apiKey>>',
            toEmail = '<<emailAddress>>',
            toNames = '<<myName>>',
            message = {
                'html': 'Yo, this is the <b>html</b> portion',
                'text': 'Yo, this is the *text* portion',
                'subject': 'This is the subject',
                'from_name': 'Me!',
                'from_email': '',
                'to_email': toEmail,
                'to_name': toNames
            },
            tags = ['HelloWorld'],
            params = {
                'apikey': apiKey,
                'message': message,
                'track_opens': true,
                'track_clicks': false,
                'tags': tags
            },
            url = 'https://us13.api.mailchimp.com/3.0/SendEmail';
    needle.post(url, params, function(err, headers) {
        if (err) {
                    console.error(err);
                }
                console.log(headers);
        }
    });
    

    I keep getting a 401 response (not authorized because I'm not sending the API key properly)

    I have to use needle due to the constraints on the server.

  • Tay Moore
    Tay Moore about 8 years
    Does 'anystring' need to be something specific or can it literally be any string. I've tried this but I'm still getting a 401 error.
  • Tay Moore
    Tay Moore about 8 years
    So this fixed it, I had a typo in username.
  • TooMuchPete
    TooMuchPete about 8 years
    While this is true about authentication, it's worth noting that SendEmail is not a valid API v3 endpoint.
  • Tay Moore
    Tay Moore about 8 years
    This is the correct answer. It should also be mentioned that even if this did work, I didn't set up the authentication correctly. @micmia mentions the correct way to setup the authentication.
  • Tay Moore
    Tay Moore about 8 years
    before I start a new question, any idea why this would return a 405 (Method not allowed) var apiKey = '<<apikey>>', url = 'us13.api.mailchimp.com/3.0/campaigns/<<campaign>>/…'; try { needle.post(url, {username: 'anystring', password: apiKey}, function(err, headers) { if (err) { console.error(err); } console.log(headers);
  • TooMuchPete
    TooMuchPete about 8 years
    Method Not Allowed is a standard HTTP error. It means that the HTTP method you're using (in this case POST) is not valid for the resource you selected. MailChimp uses HTTP methods to distinguish between operations. POST for create, GET for read, etc. So how to fix that particular problem depends on what you're trying to do, but you'll either want to use a different method (PATCH or GET) or use a different endpoint (like /campaigns/)
  • Tay Moore
    Tay Moore about 8 years
    Excellent answer, turns out I had the wrong campaign ID. I'm leaving a comment here so others know that I'm going to use Mandrill to get the job done. If you have a MailChimp subscription already, then you can use Mandrill to send messages. It's a better API (in my opinion) for this task.