Skip to content

Add the campaign subscription topic and campaigns webhooks - #273

Open
Rabsztok wants to merge 3 commits into
add-subscription-topics-to-the-sdks-andfrom
add-campaign-subscription-topic-and-campaigns-webhooks
Open

Rabsztok wants to merge 3 commits into
add-subscription-topics-to-the-sdks-andfrom
add-campaign-subscription-topic-and-campaigns-webhooks

Conversation

@Rabsztok

@Rabsztok Rabsztok commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Motivation

With subscription topics, a campaign can be sent under a topic, and the API adds a campaigns webhook type and a subscription_preferences_update webhook event. This brings both to the .NET SDK.

It builds on #271 (the Subscription Topics API), which the campaign example uses to pick a topic.

Changes

  • campaigns can be created and updated with a subscription topic, and campaign responses return it; it is left out of the request unless set
  • webhooks gain the subscription_preferences_update event and the campaigns webhook type, which requires event types and takes no sending stream
  • the campaign and webhook examples show them

How to test

You'll need API tokens for two accounts: one with subscription topics (at least one topic, a verified sending domain and a draft campaign) and one without.

Campaigns

  • Create and update a draft with SubscriptionTopicId set to a topic covering its domain; the response returns it, and a later GetDetails too
  • A deleted topic or one that doesn't cover the campaign's domain: the API answers 422
  • Account without topics: the same request succeeds and the campaign has no topic

Webhooks

  • Create a campaigns webhook with delivery and subscription_preferences_update: it is created and lists both event types
  • subscription_preferences_update on a transactional email_sending webhook: the API answers 422

Examples

  • Run the campaign and webhook examples against both accounts: they complete, and the topic steps are skipped on the account without topics

PR Train

# PR Base
1 #271 Subscription Topics API (list and get) main
2 #272 Subscription topic preferences on contacts and contact imports #271
3 #273 Campaign subscription topic and campaigns webhooks #271

Split out of the same change but outside this train, targeting main on its own: #274 (email-log topic events and topic unsubscriptions in suppressions).

Decisions:
- The topic is left out of campaign create and update requests unless set
- Campaigns webhooks validate like the API: event types required, no sending stream
- email_sending and campaigns webhooks share the event-types rule

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

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a28052fd-8482-4cf7-bdb4-6c3632634e0d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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.

@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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.

Decisions:
- The shared email_sending/campaigns EventTypes rule listed both types, so an
  email_sending caller got an error mentioning campaigns; the message now names
  the request's own type, as it did before campaigns webhooks were added.
- Build the campaigns webhook test request in one helper instead of four times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rabsztok
Rabsztok marked this pull request as ready for review November 23, 2026 11:29
@Rabsztok
Rabsztok requested a review from mklocek as a code owner November 23, 2026 11:29
Decisions:
- Pin the email_sending EventTypes message, which only the campaigns side covered
- Keep the validator's tests in one fixture, as other resources do

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
/// Available only for <c>campaigns</c> webhooks and <c>email_sending</c> webhooks of the bulk stream;
/// the API rejects it for the transactional stream.
/// </remarks>
public static readonly WebhookEventType SubscriptionPreferencesUpdate = Define("subscription_preferences_update");

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] The live API doesn't accept subscription_preferences_update yet – it quietly drops event types it doesn't know. So today a campaigns webhook created with delivery and this event comes back with only delivery, a webhook with just this event gets a 422 "can't be blank", and a transactional webhook isn't refused. Could you hold this value and the example lines that use it until the API change that adds the event is live, or release them separately from the campaign topic and the campaigns type, which already work?

.WithMessage("'SendingStream' must not be set for 'campaigns' webhook type.");
});

When(r => r.WebhookType == WebhookType.EmailSending || r.WebhookType == WebhookType.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.

[could] No test covers the email_sending half of this condition. I dropped r.WebhookType == WebhookType.EmailSending || and every unit and integration test still passed, so an email_sending webhook without event types (and the new interpolated message) isn't checked anywhere. A case next to Validate_CampaignsWebhookWithoutEventTypes_ShouldFail for email_sending would cover it.

/// </value>
///
/// <remarks>
/// For an account without subscription topics, the API ignores this field.

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.

[nitpick] The API ignores this field only when subscription topics aren't enabled for the account. An account that has the feature but no topic with this ID gets a 422 "does not exist", so "an account without subscription topics" reads wrong for that case. The same sentence is in UpdateEmailCampaignRequest.

@Rabsztok
Rabsztok marked this pull request as draft November 23, 2026 21:46

@mklocek mklocek left a comment

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.

LGTM. +1 to @oshchyhol on not releasing subscription_preferences_update before the API accepts it. Small one: subscription_topic_id on campaigns isn't in mailtrap-openapi yet either, so it'd be good to land it in the spec before the release so docs and the other SDKs line up.

@Rabsztok

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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.

@Rabsztok
Rabsztok marked this pull request as ready for review November 24, 2026 13:14

This branch has not been deployed

No deployments
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.

4 participants