Adding tags to a mailingΒΆ

Below is a sample function written in python showing how to add tags to a mailing.

import requests

AK_USERNAME = '' # Enter your username
AK_PASSWORD = '' # Enter your password

def tag_mailing(mailing_id, tag_ids):

    """ Applies tags to a mailing with the given mailing_id.
            tag_ids: a list of tag IDs. Use a list.

    resource_uri = '/rest/v1/mailing/{0}/'.format(mailing_id)
    tags = ['/rest/v1/tag/{0}/'.format(tag_id) for tag_id in tag_ids]

    response = requests.put(
            'tags': tags

    if response.status_code == 204:
        return "Successfully applied tags {0} to mailing #{1}".format(
            ', '.join([str(tag_id) for tag_id in tag_ids]),

With that function defined, you'll be able to use tag_mailing() with a given mailing_id and tag_ids, like: tag_mailing(11111, [123, 234, 345]) which will add the tags that have the IDs 123, 234, and 345 to the mailing with the ID 11111.

Note that this will overwrite any existing tags previously applied to this mailing. If you wish to add new tags while keeping existing tags, be sure to issue a requests.get() to the resource_uri first, retrieve the existing tags, and include those IDs in tag_ids.