I had created the mail subscription using mailchimp. The mail id is listed in the lists of mailchimp, but i want to pass the firstname,lastname and want to create a tag while doing the mailchimp subscription. but now i am listing only the mail under my list.. when i am trying to create the tag via postman, the tags are created, but i want to add through api code.
var mailchimpInstance = '***',
listUniqueId = '*********',
mailchimpApiKey = '*****************';
app.post('/signup', function (req, res) {
request
.post('https://' + mailchimpInstance + '.api.mailchimp.com/3.0/lists/' + listUniqueId + '/members/')
.set('Content-Type', 'application/json;charset=utf-8')
.set('Authorization', 'Basic ' + new Buffer('any:' + mailchimpApiKey ).toString('base64'))
.send({
'email_address': req.body.email,
'status': 'subscribed',
'merge_fields': {
"FNAME": req.body.fname,
"LNAME": req.body.lname
}
})
.end(function(err, response) {
if (response.status < 300 || (response.status === 400 && response.body.title === "Member Exists")) {
res.send('Sign Up Success :)');
} else {
res.send('Sign Up Failed :(');
}
console.log(req.body.email);
});
});
This code is for sending the email to the lists..in this code the firstname and lastname is not listed in the lists of mailchimp..and i also need to create tags using this api
There's a 'tags' body parameter which accepts an array and adds the tags to the mail id. Here's the documentation: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#%20
If you want to create an email address AND add tags, you need to specify the tag as an array in the members field.
This drove me nuts as I noticed it had for a lot of other people reading through Stackoverflow.
In your code, you would add the below when you are calling send.
In the below example, I had already created a tag:
var data = {
status: "active",
members:[
{
tags: ["yourtagname"],
email_address: email,
status: "subscribed",
merge_fields: {
FNAME: firstName,
LNAME: lastName,
},
}
],
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.