SendGrid: Group Unsubscribes, Add Emails
Adds Email addresses to the SendGrid Group Unsubscribe list.
  • C1: Authorization Setting in which API Token is set *
  • C2: Unsubscribe Group ID *#{EL}
  • C3: emails(500 or less. Separate with a new line.) *#{EL}
Script (click to open)


function addEmailToUnsubscribeGroup(){

    const auth = configs.get("conf_auth");
    const url = createRequestUrl();
    const recipientsObj = createRecipientsObj();

    const response = httpClient.begin()
    .body(JSON.stringify(recipientsObj),"application/json; charset=UTF-8")

    const httpStatus = response.getStatusCode();
    engine.log("HTTP Status: " + String(httpStatus));
    if(httpStatus !== 201){
        throw "adding recipient emails failed.";


function createRecipientsObj(){

    const recipientEmailsList = configs.get("conf_recipient_emails"); //複数行
    const recipientsObj = {};
    recipientsObj["recipient_emails"] = [];
    const recipientEmails = recipientEmailsList.trim().split("\n");

    for(let i = 0 ; i < recipientEmails.length ; i++){

        //一度に emails に追加できるのは 500 件まで(SendGrid の仕様)
        if(i === 500){ 
            engine.log("No more than 501 items will be registered.");

        recipientsObj["recipient_emails"][i] = recipientEmails[i].trim();


    return recipientsObj;


function createRequestUrl(){
    const unsubscribeGroupId = configs.get("conf_unsubscribe_group_id");
    const requestUrl = "" + unsubscribeGroupId + "/suppressions";
    return requestUrl;


2021-09-30 (C) Questetra, Inc. (MIT License)
The Add-on import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.


  • In the HTTP Authorization Settings of the workflow App in which this Add-on is to be used, add the API Key that you created in SendGrid under Settings > API Keys.


%d bloggers like this: