3

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
  • 137
  • 1
  • 1
  • 12

2 Answers2

2

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.

TooMuchPete
  • 4,583
  • 2
  • 17
  • 21
  • 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 Apr 12 '16 at 16:55
  • before I start a new question, any idea why this would return a 405 (Method not allowed) var apiKey = '<>', url = 'https://us13.api.mailchimp.com/3.0/campaigns/<>/actions/send'; try { needle.post(url, {username: 'anystring', password: apiKey}, function(err, headers) { if (err) { console.error(err); } console.log(headers); – Tay Moore Apr 12 '16 at 17:02
  • Method Not Allowed is a [standard HTTP error](http://www.checkupdown.com/status/E405.html). 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/) – TooMuchPete Apr 12 '16 at 17:33
  • 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. – Tay Moore Apr 12 '16 at 19:07
1

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.

Community
  • 1
  • 1
micmia
  • 1,371
  • 1
  • 14
  • 29