Skip to main content

Overview

The Contact Management API provides full CRUD operations for managing CRM contacts, including subscribers, leads, and members.

Methods

getAll

Retrieve all contacts in the CRM.
db.crm.getAll(): Contact[]
contacts
Contact[]
Array of all contacts
Example:
const contacts = db.crm.getAll();
console.log(`Total contacts: ${contacts.length}`);

getById

Find a specific contact by ID.
db.crm.getById(id: string): Contact | undefined
id
string
required
The unique contact ID
contact
Contact | undefined
The contact object if found, undefined otherwise
Example:
const contact = db.crm.getById('c_12345');
if (contact) {
  console.log('Contact:', contact.name, contact.email);
}

add

Create a new contact.
db.crm.add(contact: Omit<Contact, 'id'>): Contact
contact
Omit<Contact, 'id'>
required
Contact data without ID (auto-generated)
contact
Contact
The newly created contact with generated ID
Example:
const newContact = db.crm.add({
  name: 'Juan Pérez',
  email: '[email protected]',
  phone: '+56912345678',
  role: 'Member',
  status: 'Subscribed',
  lastContact: '2024-03-15',
  tags: ['Newsletter', 'Meditation']
});

update

Update an existing contact.
db.crm.update(contact: Contact): Contact[]
contact
Contact
required
Complete contact object with updates
contacts
Contact[]
Updated array of all contacts
Example:
const contact = db.crm.getById('c_12345');
if (contact) {
  contact.status = 'Subscribed';
  contact.tags = [...contact.tags, 'VIP'];
  db.crm.update(contact);
}

addLead

Quickly add a lead from a subscription form.
db.crm.addLead(lead: {
  email: string;
  source: string;
  date: string;
  status: string;
}): Promise<Contact>
lead.email
string
required
Lead’s email address
lead.source
string
required
Lead source (e.g., ‘Footer’, ‘Landing Page’)
lead.date
string
required
Date captured (ISO format)
lead.status
string
required
Initial status
contact
Contact
The created contact record
Example:
const lead = await db.crm.addLead({
  email: '[email protected]',
  source: 'Footer Newsletter',
  date: new Date().toISOString(),
  status: 'Subscribed'
});

addMultiple

Bulk import multiple contacts.
db.crm.addMultiple(contacts: Omit<Contact, 'id'>[]): Contact[]
contacts
Omit<Contact, 'id'>[]
required
Array of contacts to import
contacts
Contact[]
Array of newly created contacts with IDs
Example:
const imported = db.crm.addMultiple([
  { name: 'Ana García', email: '[email protected]', phone: '', role: 'Lead', status: 'Pending', lastContact: '2024-03-15', tags: [] },
  { name: 'Carlos López', email: '[email protected]', phone: '', role: 'Lead', status: 'Pending', lastContact: '2024-03-15', tags: [] }
]);
console.log(`Imported ${imported.length} contacts`);

Contact Type

interface Contact {
  id: string;
  name: string;
  firstName?: string;
  lastName?: string;
  email: string;
  phone: string;
  role: string;
  status: 'Subscribed' | 'Unsubscribed' | 'Bounced' | 'Pending' | 'new';
  lastContact: string;
  tags: string[];
  notes?: string;
  engagementScore?: number; // 0-100
  mailrelayId?: string;
  city?: string;
  country?: string;
  createdAt?: string;
  listIds?: string[]; // List memberships
}

Integration with Mailrelay

Sync contacts with Mailrelay service.

syncContact

db.mailrelay.syncContact(contact: Contact): Promise<Contact>
contact
Contact
required
Contact to sync with Mailrelay
contact
Contact
Updated contact with mailrelayId
Example:
const synced = await db.mailrelay.syncContact(contact);
console.log('Mailrelay ID:', synced.mailrelayId);

Build docs developers (and LLMs) love