MT-22401: Add Email Campaigns API - #148
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 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 |
|
Applied the same fix CodeRabbit raised on the Python PR: |
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; domain_id is the numeric sending-domain ID from the Sending Domains endpoints; template_attributes shared between create and update with no template id
ac3adfd to
47c3416
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/email-campaigns/everything.ts`:
- Around line 62-66: Replace the hard-coded past datetime in the schedule call
with an execution-relative future time, and update the statistics request to
omit the fixed May 2026 filter or generate a window covering the campaign’s
actual send time. Preserve the subsequent cancellation, sending, termination,
statistics, and deletion flow in the example.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a6faa18b-135f-4a61-a765-a94f584cc216
📒 Files selected for processing (8)
README.mdexamples/email-campaigns/everything.tssrc/__tests__/lib/api/EmailCampaigns.test.tssrc/__tests__/lib/api/resources/EmailCampaigns.test.tssrc/lib/MailtrapClient.tssrc/lib/api/EmailCampaigns.tssrc/lib/api/resources/EmailCampaigns.tssrc/types/api/email-campaigns.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- README.md
- src/tests/lib/api/EmailCampaigns.test.ts
- src/lib/MailtrapClient.ts
- src/lib/api/EmailCampaigns.ts
- src/tests/lib/api/resources/EmailCampaigns.test.ts
- src/types/api/email-campaigns.ts
- src/lib/api/resources/EmailCampaigns.ts
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
47c3416 to
d5a81a9
Compare
Decisions: - Nothing in the payload is campaign-specific; the next paginated resource should reuse it rather than redeclare it
Decisions:
- "/api/accounts/{account_id}/email_campaigns" does not exist, so there is no
need to contrast the real path against it
- Keep the positive fact that the account comes from the API token; it explains
why the path takes no account id
| * Delete an email campaign by ID. The campaign must not be in a sending | ||
| * state. Returns nothing (204 No Content). |
There was a problem hiding this comment.
| * Delete an email campaign by ID. The campaign must not be in a sending | |
| * state. Returns nothing (204 No Content). | |
| * Delete an email campaign by ID. Only a campaign in the draft state can be deleted. | |
| * Returns nothing (204 No Content). |
| - Custom fields CRUD – [`contact-fields/everything.ts`](examples/contact-fields/everything.ts) | ||
| - Import/Export – [`contact-imports/everything.ts`](examples/contact-imports/everything.ts), [`contact-exports/everything.ts`](examples/contact-exports/everything.ts) | ||
| - Events – [`contact-events/everything.ts`](examples/contact-events/everything.ts) | ||
| - Email campaigns CRUD, lifecycle & stats – [`email-campaigns/everything.ts`](examples/email-campaigns/everything.ts) |
There was a problem hiding this comment.
is "Contact management:" the correct section for this?
Decisions: - The backend allows deleting only a campaign in the draft state (EmailCampaign#validate_soft_delete), not merely a non-sending one - Examples deleted a campaign after start/terminate, which would 422; a started campaign can never return to draft, so they now delete a fresh draft
Decisions: - Campaigns are an Email Marketing feature, not contact management or Email API/SMTP, so they were filed under the wrong heading
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), numericdomain_id(matching the Sending Domains endpoints ids),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