Skip to content

MT-22654: Document tracking opt-outs public API#46

Open
leonid-shevtsov wants to merge 1 commit into
mainfrom
MT-22654-tracking-opt-outs-openapi
Open

MT-22654: Document tracking opt-outs public API#46
leonid-shevtsov wants to merge 1 commit into
mainfrom
MT-22654-tracking-opt-outs-openapi

Conversation

@leonid-shevtsov

@leonid-shevtsov leonid-shevtsov commented Jun 26, 2026

Copy link
Copy Markdown

Motivation

https://railsware.atlassian.net/browse/MT-22654

Changes

  • Add tracking-opt-outs tag and CRUD paths in email-sending.openapi.yml (GET/POST /api/tracking_opt_outs, DELETE /api/tracking_opt_outs/{id})
  • Document list filters (email, start_time, end_time, last_id), pagination limit, and rate limits
  • Add TrackingOptOut schema and response components matching Falcon v2 shapes
  • Document tracking_opt_out_enabled on sending domain GET/PATCH

How to test

  • New Tracking Opt-Outs section appears under Email Sending API docs after merge

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added support for managing tracking opt-outs through the API.
    • Introduced endpoints to list, create, and remove tracking opt-outs.
    • Added tracking opt-out settings to domain configuration, including an enable/disable option.
  • Bug Fixes

    • Clarified when recipients can opt out of open and click tracking, based on tracking being enabled.

Decisions:
- Mirror suppressions path style (`/api/tracking_opt_outs`) for account-scoped v2 endpoints
- SDK samples deferred until client libraries ship tracking opt-out support

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The OpenAPI spec adds tracking opt-out documentation, domain setting fields, and new list/create/delete tracking opt-out endpoints with supporting parameters, schemas, and responses.

Changes

Tracking opt-out OpenAPI additions

Layer / File(s) Summary
Docs overview
specs/email-sending.openapi.yml
API descriptions and the new tracking-opt-outs tag section mention tracking opt-outs.
Domain setting
specs/email-sending.openapi.yml
Domain and UpdateDomainRequest add tracking_opt_out_enabled, and the domain PATCH example includes it.
Tracking opt-out endpoints
specs/email-sending.openapi.yml
The list, create, and delete tracking opt-out paths add filters, pagination, a path parameter, a TrackingOptOut schema, and response components.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through specs with a cheerful grin,
Tracking opt-outs now neatly sit within.
A little flag, a path, a schema bright,
The API moon glows soft tonight.
Thump-thump, the docs are tidy and light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: documenting the tracking opt-outs public API.
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.
Description check ✅ Passed The PR description follows the template well with Motivation, Changes, and How to test sections; only the optional Images and GIFs section is missing.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch MT-22654-tracking-opt-outs-openapi

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.

@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: 2

🤖 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-sending.openapi.yml`:
- Around line 1422-1431: The create/delete tracking opt-outs docs only include
cURL, so the standard code sample tabs are missing for these operations. Update
the x-codeSamples blocks in the tracking_opt_outs POST/DELETE sections to follow
the repo’s usual priority order: cURL, Node.js, PHP, Python, Ruby, .NET, and
Java, and include the same explicit “SDK does not yet support tracking opt-outs”
limitation note for the unsupported SDK entries. Use the existing tracking
opt-outs sample patterns in this spec to keep the language ordering and
messaging consistent.
- Around line 1323-1368: The Node.js x-codeSamples entry for tracking opt-outs
mixes a MailtrapClient instantiation with a raw fetch call, which is misleading
because it implies SDK support that does not exist. Update the JavaScript sample
to match the other language blocks by replacing the example in the tracking
opt-outs section with an SDK-limitation note, and remove the
MailtrapClient/getTrackingOptOuts sample so readers are directed to the cURL
example until the SDK supports this endpoint.
🪄 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: 9fc7721e-0a63-4262-ab46-ae21764c1070

📥 Commits

Reviewing files that changed from the base of the PR and between 14e1854 and a3286eb.

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

Comment on lines +1323 to +1368
- lang: javascript
label: Node.js
source: |
import { MailtrapClient } from "mailtrap";

const client = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY,
accountId: YOUR_ACCOUNT_ID
});

async function getTrackingOptOuts() {
const response = await fetch(
"https://mailtrap.io/api/tracking_opt_outs",
{ headers: { Authorization: `Bearer ${process.env.MAILTRAP_API_KEY}` } }
);
const trackingOptOuts = await response.json();
console.log("Tracking opt-outs:", trackingOptOuts);
}

getTrackingOptOuts();
- lang: php
label: PHP
source: |
<?php
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: python
label: Python
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: ruby
label: Ruby
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: csharp
label: .NET
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: java
label: Java
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace the Node.js fetch sample with an SDK-limitation note.

The JavaScript block is labeled as a Node.js x-codeSamples entry but does not use the Mailtrap SDK; it constructs a MailtrapClient and then falls back to raw fetch. That contradicts the stated “SDKs are deferred until support exists” approach and will mislead readers into assuming JS SDK support already exists.

Suggested change
         - lang: javascript
           label: Node.js
           source: |
-            import { MailtrapClient } from "mailtrap";
-
-            const client = new MailtrapClient({
-              token: process.env.MAILTRAP_API_KEY,
-              accountId: YOUR_ACCOUNT_ID
-            });
-
-            async function getTrackingOptOuts() {
-              const response = await fetch(
-                "https://mailtrap.io/api/tracking_opt_outs",
-                { headers: { Authorization: `Bearer ${process.env.MAILTRAP_API_KEY}` } }
-              );
-              const trackingOptOuts = await response.json();
-              console.log("Tracking opt-outs:", trackingOptOuts);
-            }
-
-            getTrackingOptOuts();
+            // Mailtrap SDK does not yet support tracking opt-outs.
+            // Use the cURL example above.

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."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- lang: javascript
label: Node.js
source: |
import { MailtrapClient } from "mailtrap";
const client = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY,
accountId: YOUR_ACCOUNT_ID
});
async function getTrackingOptOuts() {
const response = await fetch(
"https://mailtrap.io/api/tracking_opt_outs",
{ headers: { Authorization: `Bearer ${process.env.MAILTRAP_API_KEY}` } }
);
const trackingOptOuts = await response.json();
console.log("Tracking opt-outs:", trackingOptOuts);
}
getTrackingOptOuts();
- lang: php
label: PHP
source: |
<?php
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: python
label: Python
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: ruby
label: Ruby
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: csharp
label: .NET
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: java
label: Java
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: javascript
label: Node.js
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: php
label: PHP
source: |
<?php
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: python
label: Python
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: ruby
label: Ruby
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: csharp
label: .NET
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: java
label: Java
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
🤖 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-sending.openapi.yml` around lines 1323 - 1368, The Node.js
x-codeSamples entry for tracking opt-outs mixes a MailtrapClient instantiation
with a raw fetch call, which is misleading because it implies SDK support that
does not exist. Update the JavaScript sample to match the other language blocks
by replacing the example in the tracking opt-outs section with an SDK-limitation
note, and remove the MailtrapClient/getTrackingOptOuts sample so readers are
directed to the cURL example until the SDK supports this endpoint.

Source: Coding guidelines

Comment on lines +1422 to +1431
x-codeSamples:
- lang: shell
label: 'cURL'
source: |
curl -X POST https://mailtrap.io/api/tracking_opt_outs \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"email": "tracked@example.com"
}'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add the missing language sample slots for create/delete tracking opt-outs.

Line 1422 and Line 1469 only provide cURL. For spec files in this repo, x-codeSamples should still keep the standard language order, and unsupported SDK entries should be present with an explicit limitation note. Right now the POST/DELETE docs will lose the usual tabs and won’t communicate why the SDK samples are missing.

Based on learnings, populate x-codeSamples in the exact priority order with cURL first, then Node.js, PHP, Python, Ruby, .NET, and Java, using the same “SDK does not yet support tracking opt-outs” note you already added elsewhere.

Also applies to: 1469-1474

🧰 Tools
🪛 Betterleaks (1.5.0)

[high] 1426-1427: 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-sending.openapi.yml` around lines 1422 - 1431, The create/delete
tracking opt-outs docs only include cURL, so the standard code sample tabs are
missing for these operations. Update the x-codeSamples blocks in the
tracking_opt_outs POST/DELETE sections to follow the repo’s usual priority
order: cURL, Node.js, PHP, Python, Ruby, .NET, and Java, and include the same
explicit “SDK does not yet support tracking opt-outs” limitation note for the
unsupported SDK entries. Use the existing tracking opt-outs sample patterns in
this spec to keep the language ordering and messaging consistent.

Sources: Coding guidelines, Learnings

Comment on lines +1328 to +1331
const client = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY,
accountId: YOUR_ACCOUNT_ID
});

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.

This example do not use client, so if we want keep it - fetch is enough, but I think we should stick with curl only

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.

Yep, if an SDK doesn't support it yet we just don't give an example here, not even that "does not yet support" comment, leaving only cURL.

Comment on lines +1343 to +1368
- lang: php
label: PHP
source: |
<?php
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: python
label: Python
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: ruby
label: Ruby
source: |
# Mailtrap SDK does not yet support tracking opt-outs.
# Use the cURL example above.
- lang: csharp
label: .NET
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.
- lang: java
label: Java
source: |
// Mailtrap SDK does not yet support tracking opt-outs.
// Use the cURL example above.

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.

should we list those at all if we do not implement it? For other endpoints we just leave cURL (example: https://docs.mailtrap.io/developers/email-sending/email-logs)

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