MT-22401: Add Email Campaigns API - #148
Conversation
Decisions:
- Request bodies are flat (no email_campaign wrapper) per the current OpenAPI contract
- Single-object and stats responses keep the {data} envelope (Webhooks convention; the axios interceptor only unwraps the HTTP body)
- delete() returns void — the API responds 204 No Content
- Added the five lifecycle endpoints (start/schedule/cancel/terminate/reset) with schedule taking {datetime}
- current_state typed as the 10-value enum; mailsend_domain_id is a string UUID; template_attributes shared between create and update with no template id
📝 WalkthroughWalkthroughAdds a typed Email Campaigns API with CRUD, lifecycle actions, scheduling, termination, reset, statistics, MailtrapClient exposure, Axios-mock tests, and an end-to-end example documented in the README. ChangesEmail campaigns integration
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant MailtrapClient
participant EmailCampaignsBaseAPI
participant EmailCampaignsApi
participant MailtrapAPI
Client->>MailtrapClient: access emailCampaigns
MailtrapClient->>EmailCampaignsBaseAPI: construct accessor with shared Axios instance
EmailCampaignsBaseAPI->>EmailCampaignsApi: bind campaign methods
EmailCampaignsApi->>MailtrapAPI: send CRUD or lifecycle request
MailtrapAPI-->>EmailCampaignsApi: return campaign, stats, or error
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Decisions: - The endpoint is token-scoped and resolves the account server-side, so requiring accountId made a valid token-only client unusable (matches the inbound getter precedent and the fix applied to the Python SDK) - Example no longer configures accountId
|
Applied the same fix CodeRabbit raised on the Python PR: |
Motivation
MT-22401
Port the Email Campaigns public API (MT-21113) to the Node.js SDK. The MCP server's campaigns tools depend on this landing and being released to npm.
Changes
client.emailCampaignscovering the full contract:getList(page-token pagination + search),get,create,update,delete(204 →void), the five lifecycle actions (start,schedule,cancel,terminate,reset), andgetStatswith an optional date range{data}response envelopes (Webhooks convention), UUIDmailsend_domain_id,rapid/gradualdelivery modes, 10-valueCampaignState, audience id arrays,TemplateAttributes(subjectrequired on create) withbody_html/body_text/merge_tags, per-recipient state-metadata errorsexamples/email-campaigns/everything.ts+ README bulletHow to test
examples/email-campaigns/everything.tswith a real API token and a verified sending domain — create a draft, update design/audience, schedule + cancel, fetch stats, deletecancelon a draft) surfaces the API error messageSummary by CodeRabbit
New Features
Documentation
Tests