TypeScript SDK

The official TypeScript SDK provides typed methods for all 222+ API operations with built-in authentication, retry logic, and error handling.

Installation

npm install @cakemail-org/cakemail-sdk

Quick start

import { CakemailClient } from '@cakemail-org/cakemail-sdk';

const client = new CakemailClient({
  email: 'you@example.com',
  password: 'your-password',
});

// List campaigns
const campaigns = await client.campaignService.listCampaigns({
  page: 1,
  perPage: 10,
});

// Create a contact
const contact = await client.contactService.addContact({
  listId: 123,
  requestBody: {
    email: 'new-subscriber@example.com',
  },
});

Authentication

The SDK handles OAuth2 automatically. Provide email/password and it manages token acquisition, caching, and refresh:

// Email/password auth (recommended)
const client = new CakemailClient({
  email: 'you@example.com',
  password: 'your-password',
});

// Or use a pre-existing access token
const client = new CakemailClient({
  accessToken: 'your-access-token',
});

Error handling

import { CakemailAPIError } from '@cakemail-org/cakemail-sdk';

try {
  await client.campaignService.getCampaign({ campaignId: 999 });
} catch (error) {
  if (error instanceof CakemailAPIError) {
    console.log(error.statusCode);     // 404
    console.log(error.message);        // "Campaign not found"
    console.log(error.requestId);      // For support debugging
  }
}

Available services

The SDK exposes one service per API resource:

ServiceDescription
accountServiceAccount management
campaignServiceCampaign lifecycle
contactServiceContact CRUD, import, tags
listServiceList management
templateServiceEmail templates
senderServiceSender management
webhookServiceWebhook management
emailApiServiceTransactional email (v2)
reportServiceAnalytics and stats
tagServiceContact tags
segmentServiceList segmentation

And 20+ more services covering the full API.

Multi-account support

For partner/reseller operations, pass accountId to any service method:

const campaigns = await client.campaignService.listCampaigns({
  accountId: 12345,
  page: 1,
  perPage: 10,
});

Source

The SDK is open source at github.com/cakemail/cakemail-sdk.