Back to roadmaps resend Course

Managing Audiences and Contacts via Resend API

Resend provides a built-in Contacts and Audience management layer. Instead of syncing email addresses to external marketing platforms (like Mailchimp), you can store marketing contacts inside Resend.


1. What is an Audience?

An Audience represents a segregated contact list (for example, Newsletter-List or Pro-Plan-Users).

You can create an Audience list from the Resend Web Dashboard or programmatically using the SDK.


2. Managing Audiences via the SDK

A. Creating a New Audience

import { resend } from "../lib/resend";

async function buildList() {
  const audience = await resend.audiences.create({
    name: "SaaS Customers",
  });
  console.log("Created Audience ID:", audience.data?.id);
}

B. Fetching and Listing Audiences

const list = await resend.audiences.list();
console.log("Active Audience segments:", list.data);

3. Creating and Deleting Contacts

To manage user contacts inside a target audience list, use the contacts SDK methods:

async function manageContacts(audienceId: string) {
  // 1. Subscribe a user contact
  const contact = await resend.contacts.create({
    audienceId: audienceId,
    email: "subscriber@gmail.com",
    firstName: "John",
    lastName: "Doe",
    unsubscribed: false, // Set to true if the user unsubscribed
  });

  console.log("Subscribed user contact ID:", contact.data?.id);

  // 2. Remove contact from list
  await resend.contacts.remove({
    audienceId: audienceId,
    id: contact.data?.id as string,
  });

  console.log("Subscriber contact removed.");
}
Published on Last updated: