X Enterprises
fastify-xemail

lists-create

Create a new SendGrid Marketing contact list.

createList

Create a new contact list in SendGrid Marketing. The returned list.id can be passed to addContact to subscribe contacts to the new list.

Signature

fastify.xEmail.createList(name: string): Promise<{ success: boolean; list: object }>

Params

NameTypeRequiredDescription
namestringYesDisplay name for the new contact list.

Returns

Promise<{ success: boolean; list: object }>

PropertyTypeDescription
successbooleanAlways true on resolved promise.
listobjectFull SendGrid list object, including id and name.

Throws

  • [xEmail] 'name' (string) is required for createList().
  • [xEmail] Failed to create list: <reason> — SendGrid API error.

Examples

Basic — create a list

fastify.post("/admin/lists", async (request) => {
  const { name } = request.body;
  const result = await fastify.xEmail.createList(name);
  return { listId: result.list.id, name: result.list.name };
});

Realistic — create a list and subscribe the first contact

fastify.post("/campaigns/setup", async (request) => {
  const { listName, seedEmail } = request.body;

  const { list } = await fastify.xEmail.createList(listName);

  await fastify.xEmail.addContact(seedEmail, {}, [list.id]);

  await db.campaigns.create({ listId: list.id, listName });

  return { listId: list.id, subscribed: seedEmail };
});

See Also

AI Context

package: "@xenterprises/fastify-xemail"
method: fastify.xEmail.listsCreate(name)
use-when: Create a new SendGrid Marketing contact list
params: name (string)
returns: Promise<{ id: string, name: string }>
Copyright © 2026