Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailChimp API 3.0 Subscribe

I am having trouble sorting out the new MailChimp API (V3.0). It does not seem like there is a way to call a subscribe method. It seems like I have to use their Sign Up Form. Am I correct?

like image 604
Ethan Schofer Avatar asked May 30 '15 02:05

Ethan Schofer


People also ask

How do I add a subscriber to my Mailchimp API?

Go to mailchimp select account, you will find extras dropdown. Select API keys and in the bottom left you will find a button Create A Key . Click on it and your api key is created. You have to copy the API Key under the API Key header.

Can you subscribe someone on Mailchimp?

If someone has given you permission to subscribe them to your audience and receive your marketing, you can add them to your audience from the Audience dashboard in your account.

How do I manually subscribe to Mailchimp?

Resubscribe email addresses manuallyClick Audience. Click All contacts. Check the box next to the contact you want to resubscribe. Click the Actions drop-down menu, and choose Resubscribe.


2 Answers

If by "subscribe" you mean that your application will add someone to a mailing list, you may want to take a look at the List Members Collection portion of their documentation.

http://kb.mailchimp.com/api/resources/lists/members/lists-members-collection

like image 77
bryangm Avatar answered Oct 20 '22 01:10

bryangm


Adding/editing a subscriber via MailChimp v3.0 REST API.

// node/javascript specific, but pretty basic PUT request to MailChimp API endpoint
   
// dependencies (npm)
var request = require('request'),
    url = require('url'),
    crypto = require('crypto');

// variables
var datacenter = "yourMailChimpDatacenter", // something like 'us11' (after '-' in api key)
    listId = "yourMailChimpListId",
    email = "subscriberEmailAddress",
    apiKey = "yourMailChimpApiKey";

// mailchimp options
var options = {
    url: url.parse('https://'+datacenter+'.api.mailchimp.com/3.0/lists/'+listId+'/members/'+crypto.createHash('md5').update(email).digest('hex')),
    headers: {
        'Authorization': 'authId '+apiKey // any string works for auth id
    },
    json: true,
    body: {
        email_address: email,
        status_if_new: 'pending', // pending if new subscriber -> sends 'confirm your subscription' email
        status: 'subscribed',            
        merge_fields: {
            FNAME: "subscriberFirstName",
            LNAME: "subscriberLastName"
        },
        interests: {
            MailChimpListGroupId: true // if you're using groups within your list
        }
    }
};

// perform update
request.put(options, function(err, response, body) {
    if (err) {
        // handle error
    } else {
        console.log('subscriber added to mailchimp list');
    }
});
like image 28
Derek Soike Avatar answered Oct 20 '22 01:10

Derek Soike