SendGrid: Global Unsubscribes, Add Emails
Adds Email addresses to the SendGrid Global Unsubscribe list.
Configs
C1: Authorization Setting in which API Token is set *
C2: emails(500 or less. Separate with a new line.) * #{EL}
Script (click to open)
addEmailsToGlobalUnsubscribesCollection();
function addEmailsToGlobalUnsubscribesCollection(){
const auth = configs.get("conf_auth");
const url = createRequestUrl();
const recipientsObj = createRecipientsObj();
const response = httpClient.begin()
.authSetting(auth)
.body(JSON.stringify(recipientsObj),"application/json; charset=UTF-8")
.post(url);
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.");
break;
}
recipientsObj["recipient_emails"][i] = recipientEmails[i].trim();
}
return recipientsObj;
}
function createRequestUrl(){
const requestUrl = "https://api.sendgrid.com/v3/asm/suppressions/global";
return requestUrl;
}
Download
2021-09-30 (C) Questetra, Inc. (MIT License)https://support.questetra.com/addons/sendgrid-global-unsubscribes-add-emails/ The Add-on import feature is available with Professional edition. Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
Notes
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.
Capture
Like this: Like Loading...
Related