MailChimp API 3.0订阅

时间:2015-05-30 02:53:25

标签: asp.net mailchimp

我在整理新的MailChimp API(V3.0)时遇到了麻烦。似乎没有办法调用订阅方法。好像我必须使用他们的注册表格。我是对的吗?

2 个答案:

答案 0 :(得分:5)

如果通过"订阅"您的意思是您的应用程序会将某人添加到邮件列表中,您可能需要查看其文档的List Members Collection部分。

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

答案 1 :(得分:1)

通过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');
    }
});