Skip to content

Add Email Campaigns API documentation#43

Open
Rabsztok wants to merge 2 commits into
mainfrom
MT-22365-write-email-campaigns-endpoint-documentation
Open

Add Email Campaigns API documentation#43
Rabsztok wants to merge 2 commits into
mainfrom
MT-22365-write-email-campaigns-endpoint-documentation

Conversation

@Rabsztok

@Rabsztok Rabsztok commented Jun 1, 2026

Copy link
Copy Markdown

Summary

Adds a new OpenAPI 3.1 specification documenting the Email Campaigns in Marketing API.

  • New spec specs/marketing.openapi.yml covering the full campaign lifecycle:
    • GET /api/email_campaigns — list campaigns
    • POST /api/email_campaigns — create a campaign
    • GET /api/email_campaigns/{id} — retrieve a campaign
    • PATCH /api/email_campaigns/{id} — update a campaign
    • DELETE /api/email_campaigns/{id} — delete a campaign
    • GET /api/email_campaigns/{id}/stats — retrieve aggregated campaign statistics
  • Registers the spec in README.md (base URL https://mailtrap.io).
  • Tag structure set up for GitBook navigation (Email Campaigns + Campaign Stats).

Test plan

  • Validate YAML / OpenAPI 3.1 syntax
  • Confirm GitBook renders the spec correctly after merge:

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • New Email Campaigns API specification with endpoints to manage campaigns (create, retrieve, update, delete) and access aggregated delivery and engagement statistics.
  • Documentation

    • Updated README to include Marketing specification in the available specifications table.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new OpenAPI 3.1 specification for the Email Campaigns API is added with six endpoints for campaign CRUD and statistics retrieval. The specification includes authentication schemes, pagination, request/response schemas, and standardized error handling. README is updated to register the specification.

Changes

Email Campaigns OpenAPI Specification Addition

Layer / File(s) Summary
Spec registration and document initialization
README.md, specs/email-campaigns.openapi.yml (lines 1–29)
README registers the new Email Campaigns specification; OpenAPI document header declares version 3.1.0, API version 2.0.0, servers, default security requirements, and operation tags for campaign and stats endpoints.
API operations and route definitions
specs/email-campaigns.openapi.yml (lines 30–225)
Defines three REST paths: GET/POST /api/email_campaigns for listing and creating campaigns; GET/PATCH/DELETE /api/email_campaigns/{id} for retrieving, updating, and soft-deleting; GET /api/email_campaigns/{id}/stats for campaign statistics aggregates. Each operation includes parameter references, response status mappings, and example cURL payloads.
Security schemes and reusable parameters
specs/email-campaigns.openapi.yml (lines 226–277)
Introduces HeaderAuth and BearerAuth security schemes; defines reusable path parameter email_campaign_id, query parameters for token-based pagination (token, per_page), and search, each with validation constraints and example values.
Request and resource schemas
specs/email-campaigns.openapi.yml (lines 278–497)
Defines create and update request payloads with optional reply-to configuration, delivery mode, and scheduling constraints. Defines core EmailCampaign resource schema with identifiers, state metadata, optional stats, and embedded template; defines nested ReplyTo structure.
Statistics, pagination, and error response wiring
specs/email-campaigns.openapi.yml (lines 498–664)
Defines EmailCampaignStats aggregation schema with counts and rates for deliveries, opens, clicks, bounces, spam, and unsubscribes; defines Pagination metadata schema. Introduces standard error response schemas and wires named response objects for successful operations and HTTP error statuses (401, 403, 404, 422).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • leonid-shevtsov
  • IgorDobryn
  • GannaRW

Poem

🐰 Behold, the campaigns take wing!
With schemas that sing and endpoints that ring,
Stats nested deep, replies held near,
The Email Campaigns API now crystal clear!
~Signed, the README-hopping code reviewer 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description deviates significantly from the repository template, missing required sections like 'Motivation', 'Changes' list, 'How to test' with checkboxes, and 'Images and GIFs' table. Restructure the description to follow the template format with explicit 'Motivation', 'Changes' bullet list, 'How to test' checklist with checkboxes, and 'Images and GIFs' section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change: adding Email Campaigns API documentation to the repository.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MT-22365-write-email-campaigns-endpoint-documentation

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 `@specs/email-campaigns.openapi.yml`:
- Around line 59-64: The x-codeSamples block currently contains only a cURL
sample; add additional samples for Node.js (JavaScript), PHP, Python, Ruby, .NET
(C#), and Java in the same x-codeSamples array for the same endpoint so all
required languages are present in the prescribed priority (shell, javascript,
php, python, ruby, csharp, java); for Node.js and SDK-supported languages use
the official Mailtrap SDK calls with environment-variable tokens (e.g.,
process.env.MAILTRAP_API_TOKEN) and for unsupported SDK methods include a brief
comment noting the limitation and provide a vanilla HTTP example; update every
x-codeSamples occurrence (the existing x-codeSamples block and the other
occurrences mentioned) to follow this pattern and keep the lang labels matching
the required names and the source fields populated accordingly.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: b6988521-6c51-4b6a-a830-4d262e4fae98

📥 Commits

Reviewing files that changed from the base of the PR and between 697f818 and 810cc42.

📒 Files selected for processing (2)
  • README.md
  • specs/email-campaigns.openapi.yml

Comment on lines +59 to +64
x-codeSamples:
- lang: shell
label: 'cURL'
source: |
curl -X GET "https://mailtrap.io/api/email_campaigns?per_page=50&token=1" \
-H 'Api-Token: YOUR_API_TOKEN'

@coderabbitai coderabbitai Bot Jun 1, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Add code samples for all required languages.

All endpoints currently provide only cURL samples. As per coding guidelines, x-codeSamples must include all languages in this priority order: cURL (shell), Node.js (JavaScript), PHP, Python, Ruby, .NET (C#), Java. Missing samples reduce documentation completeness and user experience.

For Node.js and other SDK-supported languages, use official Mailtrap SDKs with environment variable references (e.g., process.env.MAILTRAP_API_TOKEN). If the SDK doesn't support a method, use GitBook generation or add a comment noting SDK limitations.

As per coding guidelines and retrieved learnings, x-codeSamples should include samples for: Node.js (JavaScript), PHP, Python, Ruby, .NET (C#), and Java in addition to the existing cURL samples.

Also applies to: 89-109, 128-133, 162-174, 196-201, 226-231

🧰 Tools
🪛 Betterleaks (1.3.1)

[high] 63-64: Discovered a potential authorization token provided in a curl command header, which could compromise the curl accessed resource.

(curl-auth-header)

🤖 Prompt for 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.

In `@specs/email-campaigns.openapi.yml` around lines 59 - 64, The x-codeSamples
block currently contains only a cURL sample; add additional samples for Node.js
(JavaScript), PHP, Python, Ruby, .NET (C#), and Java in the same x-codeSamples
array for the same endpoint so all required languages are present in the
prescribed priority (shell, javascript, php, python, ruby, csharp, java); for
Node.js and SDK-supported languages use the official Mailtrap SDK calls with
environment-variable tokens (e.g., process.env.MAILTRAP_API_TOKEN) and for
unsupported SDK methods include a brief comment noting the limitation and
provide a vanilla HTTP example; update every x-codeSamples occurrence (the
existing x-codeSamples block and the other occurrences mentioned) to follow this
pattern and keep the lang labels matching the required names and the source
fields populated accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add code samples once it's implemented in the SDK:
https://railsware.atlassian.net/browse/MT-22401

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rabsztok, understood! That makes sense — it's better to add SDK-based samples once the feature is fully supported rather than providing placeholder or unsupported examples.

Would you like me to open a GitHub issue on this repository to track the follow-up work of adding code samples once MT-22401 is implemented? That way it won't be forgotten after this PR merges.


🧠 Learnings used
Learnt from: dr-3lo
Repo: mailtrap/mailtrap-openapi PR: 9
File: specs/email-sending-bulk.openapi.yml:159-170
Timestamp: 2025-12-29T15:56:56.076Z
Learning: In OpenAPI spec files under specs, particularly within x-codeSamples code examples, replace actual environment variable references with clear placeholders (e.g., YOUR_API_KEY, YOUR_ACCOUNT_ID) to avoid leaking secrets in documentation. Ensure code samples show substitute values and note how users should provide real values in their environment.

Learnt from: mklocek
Repo: mailtrap/mailtrap-openapi PR: 16
File: specs/sandbox.openapi.yml:116-127
Timestamp: 2026-01-28T15:18:12.895Z
Learning: For OpenAPI specs located under specs/, populate the x-codeSamples extension with samples in this exact priority: 1) curl (shell), 2) Node.js (JavaScript), 3) PHP, 4) Python, 5) Ruby, 6) .NET (C#), 7) Java. curl should always be the default first option to align with Mailtrap's in-app integration samples.

@Rabsztok Rabsztok requested review from DagonWat and IgorDobryn June 1, 2026 07:55
x-page-title: Email Campaigns
x-page-description: Manage email marketing campaigns and their statistics

- name: Email Campaigns

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous tag had almost the same name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a parent tag, so the menu should show something like:

Email Campaigns
- Email Campaigns
- Campaign Stats 

Maybe it'd be better to create more general "Marketing" tag... What do you think?

@IgorDobryn IgorDobryn Jun 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marketing would better align with MT products

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, there is Promotional at the moment. So, maybe that's the place

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promotional is not a tag in the specs, but a custom category created in gitbook. I've rolled back the marketing rename, and removed email-campaigns parent level tag, so the end result in the menu looks like this:
Screenshot 2026-06-04 at 12 19 23
What do you think @IgorDobryn ?

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
specs/marketing.openapi.yml (1)

1-1: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Spec registration path appears out of sync with repository docs.

This file is specs/marketing.openapi.yml, but the repository listing context still points Email Campaigns to specs/email-campaigns.openapi.yml. If unchanged, discoverability and tooling references will break for this spec.

🤖 Prompt for 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.

In `@specs/marketing.openapi.yml` at line 1, The spec registration reference is
out of sync: either update the repository/docs/tooling entries that point to
"specs/email-campaigns.openapi.yml" to instead reference
"specs/marketing.openapi.yml", or rename the spec file back to
"specs/email-campaigns.openapi.yml" so the registration matches; search for
occurrences of "specs/email-campaigns.openapi.yml" in the docs/config (spec
registration/index listings, CI/spec tooling configs) and update them to the
correct filename ("specs/marketing.openapi.yml") to restore discoverability.
🤖 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 `@specs/marketing.openapi.yml`:
- Around line 63-64: The cURL samples currently embed a placeholder API token in
the URL and header; update each cURL block (e.g., the GET sample containing curl
-X GET "https://mailtrap.io/api/email_campaigns?per_page=50&token=1" and the -H
'Api-Token: YOUR_API_TOKEN' header) to use an environment variable instead:
remove the token query parameter from the URL and replace the header value with
the env var $MAILTRAP_API_TOKEN (e.g., -H "Api-Token: $MAILTRAP_API_TOKEN");
apply the same change consistently to the other cURL blocks mentioned (the
blocks around the other locations in the comment).

---

Outside diff comments:
In `@specs/marketing.openapi.yml`:
- Line 1: The spec registration reference is out of sync: either update the
repository/docs/tooling entries that point to
"specs/email-campaigns.openapi.yml" to instead reference
"specs/marketing.openapi.yml", or rename the spec file back to
"specs/email-campaigns.openapi.yml" so the registration matches; search for
occurrences of "specs/email-campaigns.openapi.yml" in the docs/config (spec
registration/index listings, CI/spec tooling configs) and update them to the
correct filename ("specs/marketing.openapi.yml") to restore discoverability.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: fb56e5f3-6f55-44f3-b0c5-ad9b0f7eaf6d

📥 Commits

Reviewing files that changed from the base of the PR and between 810cc42 and 0abbcf4.

📒 Files selected for processing (1)
  • specs/marketing.openapi.yml

Comment thread specs/email-campaigns.openapi.yml
@Rabsztok Rabsztok force-pushed the MT-22365-write-email-campaigns-endpoint-documentation branch from 0abbcf4 to 4ad75a1 Compare June 3, 2026 07:51

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (2)
specs/marketing.openapi.yml (2)

59-61: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Document SDK limitation when only cURL samples are present.

Each operation currently exposes only shell samples. Per repo rules, either provide samples in the required language order or add an explicit limitation note when SDK methods are not yet supported (e.g., MT-22401), so this spec remains guideline-compliant.

As per coding guidelines: "Use official Mailtrap SDKs for language-specific code examples in x-codeSamples; if SDK doesn't support a method, use GitBook generation or add a comment noting SDK limitations" and "Include code samples in OpenAPI specs in this priority order: cURL (shell), Node.js (JavaScript), PHP, Python, Ruby, .NET (C#), Java."

Also applies to: 89-91, 128-130, 162-164, 196-198, 226-228

🤖 Prompt for 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.

In `@specs/marketing.openapi.yml` around lines 59 - 61, The operations currently
only contain x-codeSamples with lang: shell and label: "cURL" (see x-codeSamples
entries), which violates the repo's required sample priority; either add
additional x-codeSamples in the required order (Node.js/JavaScript, PHP, Python,
Ruby, .NET/C#, Java) for each operation, or add a clear limitation note
referencing the tracker ID (e.g., MT-22401) indicating that SDK methods are not
yet supported and so only cURL is provided; update each affected x-codeSamples
block (the entries with lang: shell) and the corresponding operation description
to include that limitation note if you cannot supply the SDK examples now.

63-64: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use environment-variable style API token in all cURL samples.

Api-Token: YOUR_API_TOKEN should be shown as an environment variable reference for consistency with docs standards.

Suggested update pattern
-  -H 'Api-Token: YOUR_API_TOKEN'
+  -H "Api-Token: $MAILTRAP_API_KEY"

As per coding guidelines: "Use environment variables for API keys in code samples (e.g., process.env.MAILTRAP_API_KEY)."

Also applies to: 93-95, 132-133, 166-168, 200-201, 230-231

🤖 Prompt for 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.

In `@specs/marketing.openapi.yml` around lines 63 - 64, Replace the hard-coded API
token in the cURL examples with an environment-variable style reference: update
the Authorization header/Api-Token header occurrences (e.g., the cURL sample
starting with curl -X GET "https://mailtrap.io/api/email_campaigns...") to use
an env var placeholder like $MAILTRAP_API_TOKEN (and reference the token query
param similarly if present) and apply the same replacement to the other cURL
samples noted (the blocks around the other occurrences). Ensure the examples
consistently use the env-var style token for both header and query-param usages.
🤖 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.

Duplicate comments:
In `@specs/marketing.openapi.yml`:
- Around line 59-61: The operations currently only contain x-codeSamples with
lang: shell and label: "cURL" (see x-codeSamples entries), which violates the
repo's required sample priority; either add additional x-codeSamples in the
required order (Node.js/JavaScript, PHP, Python, Ruby, .NET/C#, Java) for each
operation, or add a clear limitation note referencing the tracker ID (e.g.,
MT-22401) indicating that SDK methods are not yet supported and so only cURL is
provided; update each affected x-codeSamples block (the entries with lang:
shell) and the corresponding operation description to include that limitation
note if you cannot supply the SDK examples now.
- Around line 63-64: Replace the hard-coded API token in the cURL examples with
an environment-variable style reference: update the Authorization
header/Api-Token header occurrences (e.g., the cURL sample starting with curl -X
GET "https://mailtrap.io/api/email_campaigns...") to use an env var placeholder
like $MAILTRAP_API_TOKEN (and reference the token query param similarly if
present) and apply the same replacement to the other cURL samples noted (the
blocks around the other occurrences). Ensure the examples consistently use the
env-var style token for both header and query-param usages.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc93d92d-7fb8-4a05-9d38-ea70eed1f329

📥 Commits

Reviewing files that changed from the base of the PR and between 0abbcf4 and 4ad75a1.

📒 Files selected for processing (2)
  • README.md
  • specs/marketing.openapi.yml
✅ Files skipped from review due to trivial changes (1)
  • README.md

@Rabsztok Rabsztok force-pushed the MT-22365-write-email-campaigns-endpoint-documentation branch from 4ad75a1 to 5cc92a8 Compare June 4, 2026 10:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
specs/email-campaigns.openapi.yml (1)

3-3: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use the official product name in the spec description.

Line 3 uses email marketing as a generic phrase. Please capitalize it to Email Marketing so the top-level docs stay consistent with the repo’s product naming rules.

Suggested fix
-  description: Manage email marketing campaigns and retrieve their performance statistics
+  description: Manage Email Marketing campaigns and retrieve their performance statistics

Based on learnings: Applies to **/*.openapi.yml : Use official product naming: 'Email API/SMTP' (can shorten to 'Email API' or 'API/SMTP'), 'Email Sandbox' (can shorten to 'Sandbox'), 'Email Marketing' (can shorten to 'Marketing')

🤖 Prompt for 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.

In `@specs/email-campaigns.openapi.yml` at line 3, Update the top-level OpenAPI
description value to use the official product naming by capitalizing "Email
Marketing" (change the string in the description field currently reading "email
marketing" to "Email Marketing") in the specs email-campaigns OpenAPI document;
search for other .openapi.yml files with similar top-level description fields
and apply the same capitalization for consistency (use "Email API/SMTP",
"Sandbox", or "Marketing" per repo naming rules where relevant).
🤖 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.

Outside diff comments:
In `@specs/email-campaigns.openapi.yml`:
- Line 3: Update the top-level OpenAPI description value to use the official
product naming by capitalizing "Email Marketing" (change the string in the
description field currently reading "email marketing" to "Email Marketing") in
the specs email-campaigns OpenAPI document; search for other .openapi.yml files
with similar top-level description fields and apply the same capitalization for
consistency (use "Email API/SMTP", "Sandbox", or "Marketing" per repo naming
rules where relevant).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dbac05fa-e49f-4124-909c-b5678f6f88d2

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad75a1 and 5cc92a8.

📒 Files selected for processing (1)
  • specs/email-campaigns.openapi.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants