How to Use ASM Tags to add Group Unsubscribes to emails sent via API or SMTP.

Enabling ASM tags. 

This options allows you to add an Unsubscribe Group to emails sent via API or SMTP by adding the ASM tag into your e-mail templates, and injecting the correct values into your mail request. 

Example:

Add the following tag In your e-mail template where you need your Unsubscribe link to be added:

 <a href="<%asm_preferences_raw_url%>">Group Unsubscribe</a>

You will need to have the Group ID for the unsubscribe group you wish to add. This can be retrieved by navigating to suppressions > Unsubscribe groups. 

In your request body, you will need to add the following field:

"asm": {
"group_id": <<add here your group ID>>
},
"groups_to_display": [
<<add here your group ID>>
],

You can also add the Global Unsubscribe link in your e-mail template by adding the following tag:

<a href="<%asm_global_unsubscribe_raw_url%>"> Global Unsubscribe</a>

This option will unsubscribe your recipients from all of your e-mails, and their e-mail addresses will be placed into the Global Unsubscribe Suppression list.

You can also use both tags to create a Recipient Preference Subscription by adding the following code in your transactional template:

<a href="<%asm_global_unsubscribe_raw_url%>">Global Unsubscribe</a>

After that, you can pass the data in the API call and add the “asm” object containing the “group_id” and “groups_to_display” values, which are both mandatory. A simple example JSON for the API call should look like this:

{
"personalizations": [
{
"to": [
{
"email": "sendgridtesting@gmail.com",
"name": SendGrid Testing Team
}
]
}
],
"from": {
"email": "SendGridTests@AuthenticatedDomain.com"
},
"reply_to": {
"email": "SendGridTests@AuthenticatedDomain.com"
},
"template_id": "d-15a56bfgh7ff740fg3a8de9dsd1a68205ab",
"asm": {
"group_id": 43762,
"groups_to_display": [
43762
]
}
}
Have more questions? Submit a request