Skip to content

MT-20639: Add email logs API docs#19

Open
mklocek wants to merge 1 commit intomainfrom
MT-20639-documentation-add-email-logs-api
Open

MT-20639: Add email logs API docs#19
mklocek wants to merge 1 commit intomainfrom
MT-20639-documentation-add-email-logs-api

Conversation

@mklocek
Copy link
Contributor

@mklocek mklocek commented Feb 25, 2026

Motivation

Changes

  • Add email logs API docs

How to test

  • Check that requests and responses match the actual structures. Rate limit for each endpoint is separate.

Images and GIFs

None.

Summary by CodeRabbit

  • New Features
    • Added endpoints to list account email sending logs and retrieve individual log messages with pagination and advanced filters.
    • Logs surface detailed event data (delivery, open, click, bounce, spam, unsubscribe, reject) and rich filter options.
  • Breaking Changes
    • Several legacy sending_domains and suppression endpoints were removed or re-scoped.

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3949a66 and 88893e6.

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

📝 Walkthrough

Walkthrough

Added an email-logs capability to the OpenAPI spec: new email-logs tag, two endpoints to list and retrieve sending messages, a sending_message_id path parameter, many new schemas for responses/filters/events, and removal of some sending_domains/suppressions endpoints.

Changes

Cohort / File(s) Summary
Email Logs API Feature
specs/email-sending.openapi.yml
Added email-logs tag; new paths GET /api/accounts/{account_id}/email_logs (operationId: listEmailLogs) and GET /api/accounts/{account_id}/email_logs/{sending_message_id} (operationId: getEmailLogMessage); new sending_message_id path parameter; introduced schemas EmailLogsListResponse, EmailLogsListFilters, SendingMessage, MessageEvent, EventDetailsDelivery, EventDetailsOpen, EventDetailsClick, EventDetailsBounce, EventDetailsSpam, EventDetailsUnsubscribe, EventDetailsReject, and filter sub-schemas (FilterTo,FilterFrom,FilterSubject,FilterStatus,FilterEvents,FilterNumber,FilterClientIp,FilterSendingIp,FilterMandatoryText,FilterExact,FilterSendingDomainId,FilterSendingStream); removed several sending_domains/suppressions endpoints in diff context.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant API as API Server
    participant Store as EmailLog Store
    participant Mailer as External Mailer

    Client->>API: GET /api/accounts/{account_id}/email_logs?filters...
    API->>Store: Query logs with filters & pagination
    Store-->>API: Return EmailLogsListResponse
    API-->>Client: 200 OK (EmailLogsListResponse)

    Client->>API: GET /api/accounts/{account_id}/email_logs/{sending_message_id}
    API->>Store: Fetch SendingMessage by id
    Store-->>API: Return SendingMessage (with MessageEvent list)
    API-->>Client: 200 OK (SendingMessage)

    Note right of Mailer: Mailer may emit events (delivery/open/click/bounce/...) that populate Store asynchronously
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I hopped through specs with nimble feet,
New logs and events now neatly meet,
Opens, clicks, bounces — all in a row,
I sniffed the filters and watched them go,
A carrot-coded cheer for the log flow! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding email logs API documentation to the OpenAPI specification.
Description check ✅ Passed The description follows the required template with all sections present. However, the Motivation section is empty and the Changes section lacks detail about the specific endpoints and schemas added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch MT-20639-documentation-add-email-logs-api

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.

@mklocek mklocek force-pushed the MT-20639-documentation-add-email-logs-api branch from 524839c to 2655700 Compare February 26, 2026 08:59
@mklocek
Copy link
Contributor Author

mklocek commented Feb 26, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mklocek mklocek force-pushed the MT-20639-documentation-add-email-logs-api branch from 2655700 to b3e2d21 Compare February 26, 2026 09:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
specs/email-sending.openapi.yml (1)

1640-1731: Consider using $ref to avoid schema duplication.

The messages array items (lines 1650-1689) duplicate the SendingMessageListItem schema definition. Using a reference would improve maintainability:

Proposed refactor
       properties:
         messages:
           type: array
           items:
-            type: object
-            properties:
-              message_id:
-                type: string
-                format: uuid
-              # ... all other properties ...
+            $ref: '#/components/schemas/SendingMessageListItem'

This would also resolve the Spectral warning about the unused SendingMessageListItem component.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@specs/email-sending.openapi.yml` around lines 1640 - 1731, The
EmailLogsListResponse schema currently inlines the message item schema under
properties.messages and duplicates the existing SendingMessageListItem
component; replace the inline items definition with a $ref to the existing
SendingMessageListItem component (e.g. items: { $ref:
'#/components/schemas/SendingMessageListItem' }) inside the
EmailLogsListResponse.messages property, remove the duplicated inline structure,
and keep the example values consistent with the referenced schema so the example
still validates; this will also address the Spectral warning about the unused
SendingMessageListItem.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@specs/email-sending.openapi.yml`:
- Around line 1733-1789: The schema SendingMessageListItem is unused; either
remove it or reference it from EmailLogsListResponse.messages.items — update
EmailLogsListResponse so its messages.items uses a $ref to
'#/components/schemas/SendingMessageListItem' (or delete the
SendingMessageListItem definition if truly unused) to resolve the Spectral
warning and keep schema usage consistent.
- Around line 1203-1208: The x-codeSamples block currently only contains a cURL
(shell) example for the email_logs GET endpoint; add additional language
examples in the required priority order (Node.js/JavaScript, PHP, Python, Ruby,
.NET/C#, Java) under x-codeSamples to match coding guidelines, using equivalent
request examples that mirror the existing curl query string and Authorization
header; if any official Mailtrap SDK lacks this endpoint, add a short comment
inside that language sample indicating the SDK limitation and provide either a
raw HTTP example or a GitBook-generation note instead.
- Around line 1247-1252: The x-codeSamples block for the GET
/accounts/{account_id}/email_logs/{sending_message_id} endpoint currently only
includes a cURL sample; add code samples for Node.js, PHP, Python, Ruby, .NET,
and Java in that priority order alongside the existing cURL entry. For the same
x-codeSamples array (the block under the GET
'https://mailtrap.io/api/accounts/{account_id}/email_logs/{sending_message_id}'
endpoint), add entries with lang and label matching existing examples (e.g.,
lang: node, php, python, ruby, csharp, java) and a source string showing an
authenticated request using the endpoint and placeholder API key, following the
style used in the list endpoint samples. Ensure each new sample uses the same
path variable placeholders ({account_id}, {sending_message_id}) and consistent
header Authorization: Bearer YOUR_API_KEY.
- Around line 1227-1239: Add a 401 Unauthorized response to the responses block
for this endpoint to match other authenticated endpoints: beneath the existing
'400' entry add a '401' response referencing the shared component (e.g. $ref:
'#/components/responses/UNAUTHORIZED' or the spec's unauthorized response name)
so the EmailLogsListResponse endpoint includes 401 alongside 200/400/404/429 for
consistent authentication docs.
- Around line 1857-1867: The events example fails oneOf validation because each
EventDetails schema is ambiguous; fix by adding a required inline discriminator
property to each EventDetails variant (e.g., add a required string property
"type" with enum values like "delivery", "open" in EventDetailsDelivery,
EventDetailsOpen, etc.), update the MessageEvent.details oneOf to use a
discriminator on the "type" property, and ensure the example objects in the
events array include the corresponding "type" values to match their schemas;
alternatively, if you prefer permissive responses, replace the oneOf for
MessageEvent.details with a single generic object schema and document the
variants instead.
- Around line 1256-1266: The responses object for this endpoint is missing the
401 Unauthorized entry; update the responses block (where '200', '404', '429'
are defined) to include a '401' response that references the shared Unauthorized
response (e.g. add '401': $ref: '#/components/responses/Unauthorized') so the
endpoint matches other authenticated endpoints.

---

Nitpick comments:
In `@specs/email-sending.openapi.yml`:
- Around line 1640-1731: The EmailLogsListResponse schema currently inlines the
message item schema under properties.messages and duplicates the existing
SendingMessageListItem component; replace the inline items definition with a
$ref to the existing SendingMessageListItem component (e.g. items: { $ref:
'#/components/schemas/SendingMessageListItem' }) inside the
EmailLogsListResponse.messages property, remove the duplicated inline structure,
and keep the example values consistent with the referenced schema so the example
still validates; this will also address the Spectral warning about the unused
SendingMessageListItem.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9764e3c and 2655700.

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

@mklocek mklocek force-pushed the MT-20639-documentation-add-email-logs-api branch 2 times, most recently from 42cf217 to 59b5a43 Compare February 26, 2026 09:12
@mklocek mklocek marked this pull request as ready for review February 26, 2026 09:14
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@specs/email-sending.openapi.yml`:
- Around line 2039-2052: The FilterSubject schema currently lists value as
required but its description allows omitting it for operator values
empty/not_empty; update the schema so value is optional for those operators and
required for the others. Modify FilterSubject (the operator enum and value
property) to either remove value from the top-level required array and add a
conditional requirement (oneOf/anyOf or if/then) that enforces value is present
when operator is not "empty"/"not_empty", or replace the single schema with two
variants: one for operator in ["empty","not_empty"] without value and one for
operators like ci_contain/ci_equal that require value. Ensure examples and
description reflect the change.
- Around line 2081-2094: The FilterNumber schema currently declares
properties.value as type: number but the description and usage (for clicks_count
and opens_count) require whole numbers; update the FilterNumber schema by
changing the value property's type from number to integer, adjust the
description to say "Numeric value (integer)" if needed, and verify any examples
or references (FilterNumber, properties.value) still use integer values (e.g.,
0) to prevent allowing decimal values.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2655700 and 59b5a43.

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

@mklocek mklocek force-pushed the MT-20639-documentation-add-email-logs-api branch from 59b5a43 to 3949a66 Compare February 26, 2026 09:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
specs/email-sending.openapi.yml (1)

43-47: Consider a more descriptive x-page-description.

Other tags have more descriptive page descriptions (e.g., "Manage verified sending domains"). For consistency:

Suggested improvement
   - name: email-logs
     x-page-title: Email Logs
-    x-page-description: Email logs
+    x-page-description: View and filter sent email logs
     description: List and retrieve email sending logs for the account.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@specs/email-sending.openapi.yml` around lines 43 - 47, Update the tag
metadata for the "email-logs" tag to use a more descriptive x-page-description
(instead of the generic "Email logs") so it matches the detail level of other
tags; locate the tag block with name: email-logs and x-page-title: Email Logs
and change x-page-description to a clearer phrase such as "List and manage email
sending logs and delivery events for the account" (or similar) so the UI page
description provides actionable context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@specs/email-sending.openapi.yml`:
- Around line 1814-1841: The MessageEvent.details oneOf is ambiguous because
several EventDetails* schemas share fields; add an OpenAPI discriminator on
MessageEvent.details with propertyName "event_type" and a mapping that links
each event_type value (delivery, open, click, soft_bounce, bounce, spam,
unsubscribe, suspension, reject) to the corresponding components/schemas
(EventDetailsDelivery, EventDetailsOpen, EventDetailsClick, EventDetailsBounce,
EventDetailsSpam, EventDetailsUnsubscribe, EventDetailsReject), and then add an
event_type property (with the correct fixed enum/value) to each EventDetails*
schema so the discriminator can unambiguously resolve which schema to validate.

---

Nitpick comments:
In `@specs/email-sending.openapi.yml`:
- Around line 43-47: Update the tag metadata for the "email-logs" tag to use a
more descriptive x-page-description (instead of the generic "Email logs") so it
matches the detail level of other tags; locate the tag block with name:
email-logs and x-page-title: Email Logs and change x-page-description to a
clearer phrase such as "List and manage email sending logs and delivery events
for the account" (or similar) so the UI page description provides actionable
context.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59b5a43 and 3949a66.

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

@mklocek mklocek force-pushed the MT-20639-documentation-add-email-logs-api branch from 3949a66 to 88893e6 Compare February 26, 2026 09:58
@mklocek
Copy link
Contributor Author

mklocek commented Feb 26, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

- lang: shell
label: 'cURL'
source: |
curl -X GET 'https://mailtrap.io/api/accounts/{account_id}/email_logs?filters[sent_after]=2025-01-01T00:00:00Z&filters[sent_before]=2025-01-31T23:59:59Z&filters[to][operator]=ci_equal&filters[to][value]=recipient@example.com&filters[sending_domain_id][operator]=equal&filters[sending_domain_id][value]=3938' \
Copy link
Contributor

Choose a reason for hiding this comment

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

for this curl to work I needed to add turn -g option, should we add it to example?

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