Skip to content

Send the Stats domain filter as sending_domain_ids[] - #35

Merged
Rabsztok merged 2 commits into
mainfrom
fix-stats-sending-domain-ids
Oct 16, 2026
Merged

Rabsztok merged 2 commits into
mainfrom
fix-stats-sending-domain-ids

Conversation

@Rabsztok

Copy link
Copy Markdown
Member

Motivation

StatsOptions.SendingDomainIDs went out as domain_ids[], but GET /api/stats and its four breakdowns read sending_domain_ids[] and silently ignore any other name. A Go caller who filtered stats by sending domain got every domain's numbers back, with no error. The parameter is sending_domain_ids[] in the spec (mailtrap/mailtrap-openapi#62 corrects its documented name), and the other SDKs already send it.

Changes

  • Stats.Get, ByDomain, ByCategory, ByEmailServiceProvider and ByDate now send SendingDomainIDs as sending_domain_ids[], so the filter narrows the stats to those domains
    • the Go API is unchanged (same field, same methods); only the query parameter name changes
    • an id that is unknown, or not visible to the token, now returns 400 instead of being ignored
    • AccountAccesses.List keeps sending domain_ids[], the name that endpoint reads

How to test

You'll need an API token for an account with at least two sending domains that both sent email in the chosen date range. Take the domain ids from the DomainID of an unfiltered ByDomain call.

  • Get, one domain — client.Stats.Get(ctx, &mailtrap.StatsOptions{StartDate: "...", EndDate: "...", SendingDomainIDs: []int64{<id>}}) returns that domain's totals only: they equal its row in the unfiltered ByDomain result and are below the unfiltered Get
  • Breakdowns, one domain — with the same options, ByDomain returns only that domain's row; ByCategory, ByEmailServiceProvider and ByDate drop to that domain's share
  • Two domains — SendingDomainIDs: []int64{<id1>, <id2>} returns the sum of the two domains' rows
  • Unknown domain — SendingDomainIDs: []int64{999999999}: err is a *mailtrap.Error with StatusCode 400 and Messages ["Sending domain does not exist: '999999999'"]
  • Regression — no filter — without SendingDomainIDs, Get and the breakdowns return all domains, as before
  • Regression — account accesses — client.AccountAccesses.List(ctx, &mailtrap.AccountAccessListOptions{DomainIDs: []int64{<id>}}) still lists only the accesses to that domain

🤖 Generated with Claude Code

Rabsztok and others added 2 commits October 13, 2026 12:06
Decisions:
- /api/stats and its breakdowns permit only sending_domain_ids[] and drop domain_ids[], so SendingDomainIDs never filtered anything
- the field name stays SendingDomainIDs; only the wire key changes, matching the OpenAPI spec and the other SDKs
- account accesses keeps domain_ids[]: that endpoint reads that name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Decisions:
- the filter now applies and rejects unknown ids with 400, so the field says which id it takes and that it can fail
- only Get checked the query name; ByDomain now does too, so a breakdown that stops sending the filter fails a test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ffb97549-3e15-48f5-82c9-fd9bf80c1540
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@Rabsztok
Rabsztok merged commit 08b0ad7 into main Oct 16, 2026
7 checks passed
@Rabsztok
Rabsztok deleted the fix-stats-sending-domain-ids branch October 16, 2026 06:45
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