Mailchimp api tags
Mailchimp's API allows you to manage tags, which are keywords or labels that you can assign to subscribers to help you segment and target your audience. Here are some common use cases for tags in Mailchimp's API:
Creating a tag
To create a new tag using the Mailchimp API, you can use the POST /tags
endpoint. The request body should contain the following information:
name
: The name of the tag.description
: A brief description of the tag.
Example request:
{
"name": "New Tag",
"description": "This is a new tag"
}
Retrieving a list of tags
To retrieve a list of all tags in your Mailchimp account, you can use the GET /tags
endpoint.
Example request:
GET https://us12.api.mailchimp.com/3.0/tags
The response will contain a list of tags, each represented by a JSON object with the following properties:
id
: The unique ID of the tag.name
: The name of the tag.description
: A brief description of the tag.
Assigning a tag to a subscriber
To assign a tag to a subscriber, you can use the POST /lists/{list_id}/members/{member_id}/tags
endpoint. The request body should contain the following information:
tag_id
: The ID of the tag you want to assign to the subscriber.
Example request:
{
"tag_id": "123456"
}
Removing a tag from a subscriber
To remove a tag from a subscriber, you can use the DELETE /lists/{list_id}/members/{member_id}/tags/{tag_id}
endpoint.
Example request:
DELETE https://us12.api.mailchimp.com/3.0/lists/{list_id}/members/{member_id}/tags/123456
Retrieving a list of subscribers with a specific tag
To retrieve a list of subscribers who have a specific tag, you can use the GET /lists/{list_id}/members/search
endpoint with the search_fields
parameter set to tags
.
Example request:
GET https://us12.api.mailchimp.com/3.0/lists/{list_id}/members/search
?search_fields=tags
&query=New+Tag
The response will contain a list of subscribers who have the specified tag.
Other tag-related endpoints
Here are some other endpoints related to tags in Mailchimp's API:
GET /tags/{tag_id}
: Retrieves information about a specific tag.PUT /tags/{tag_id}
: Updates the name or description of a tag.DELETE /tags/{tag_id}
: Deletes a tag.GET /lists/{list_id}/members/{member_id}/tags
: Retrieves a list of tags assigned to a subscriber.POST /lists/{list_id}/members/{member_id}/tags
: Assigns a tag to a subscriber.DELETE /lists/{list_id}/members/{member_id}/tags/{tag_id}
: Removes a tag from a subscriber.
Note that you need to replace {list_id}
and {member_id}
with the actual IDs of your Mailchimp list and subscriber, respectively.