Lately I have found mailchimp-api-v3 to be quite useful for managing our .1k list. Currently, I use the following to (1) create new tags, and (2) add the tag to contacts:
const MC = require('mailchimp-api-v3');
const mailchimp = new MC('<apiKey>');
mailchimp.batch([{
method: 'POST',
path: '/lists/<list_id>/segments',
body: {
name: '<tag1>',
static_segment: [<contact_list1>]
}
}, {
method: 'POST',
path: '/lists/<list_id>/segments',
body: {
name: '<tag2>',
static_segment: [<contact_list2>]
}
}])
.then(results => {
console.log( results );
})
.catch(errs => {
console.log( errs );
});
Sometimes there's need to add an existing tag to contacts. Whenever I try to use the above code, as expected, I get tag already exists error and contacts are not tagged with this existing tag.
How do I get a list of all existing tags? And how would one add an existing tag to contacts?
I finally figured out how to do that. The just updated documentation is much easier to navigate that before. It's now evident that there are two ways of adding a tag/segment to (a) member(s): you can add a single tag to a member or you can add a single tag to many members:
Bulk add with members_to_add
: array
{
method: 'POST',
path: '/lists/{list_id}/segments/{segment_id}',
body: {members_to_add: [<email-addresses>]}
}
This is indeed what I needed and I have now been using it for a while. Just today I found out the other method:
Single add with email_address
: string
{
method: 'POST',
path: '/lists/{list_id}/segments/{segment_id}/members',
email_address: {email_address}
}