Skip to main content

Group Client

Methods

constructor(auth)

Creates a new EmailClient instance.

Parameters:

NameTypeDescription
authstring | IAuthAPI key or authentication handler

Example:

const client = new EmailClient("your-api-key");

insertEmailIntoGroup(groupId, email, substitutions)

This method allows you to add a email address to a group, along with any substitutions that may be needed for personalization.

warning

You can add an email address multiple times to the same group. When sending a group email, the user will receive multiple copies of the same email.

Parameters:

NameTypeDescription
groupIdstringThe ID of the group
emailstringThe email address to add
substitutionsRecord<string, string>Substitutions for personalization. The keys should be the placeholders in the email template, and the values should be the actual values to replace them with.

Returns:

  • Promise<bool>: Promise that resolves if the email was added successfully

Example:

const client = new GroupClient("your-api-key");

const groupId = "group-id";
const email = "your@email.com";
const substitutions = {
"{{name}}": "John Doe",
"{{age}}": "30",
};

const response = await client.insertEmailIntoGroup(
groupId,
email,
substitutions
);

if (response) {
console.log("Email added to group successfully.");
} else {
console.log("Failed to add email to group.");
}

deleteEmailFromGroup(groupId, email)

This method allows you to remove a email address from a group.

info

Only emails that are added 30 minutes can be removed from the group.

Parameters:

NameTypeDescription
groupIdstringThe ID of the group
emailstringThe email address to remove

Returns:

  • Promise<bool>: Promise that resolves if the email was removed successfully

Example:

const client = new GroupClient("your-api-key");

const groupId = "group-id";
const email = "your@email.com";

const response = await client.deleteEmailFromGroup(groupId, email);

if (response) {
console.log("Email removed from group successfully.");
} else {
console.log("Failed to remove email from group.");
}

containsEmailInGroup(groupId, email)

This method checks if a email address is already in a group.

Parameters:

NameTypeDescription
groupIdstringThe ID of the group
emailstringThe email address to check

Returns:

  • Promise<bool>: Promise that resolves with true if the email is in the group, false otherwise

Example:

const client = new GroupClient("your-api-key");

const groupId = "group-id";
const email = "your@email.com";

const response = await client.containsEmailInGroup(groupId, email);

if (response) {
console.log("Email is in the group.");
} else {
console.log("Email is not in the group.");
}