Skip to Content
Recodocs

Marketing newsletter console API

Console routes for newsletter series, editions, schedules, lifecycle, inputs, revisions, and publication attestation under /api/marketing.

6 min read

What this API area is for

A newsletter series holds recurring publication work. Preparing a preview and producing an actual delivery are different states, and their route contracts should be read accordingly.

The marketing newsletter console API exposes read and write boundaries for weekly newsletter series tied to marketing campaigns. Routes live on a router with prefix /api/marketing. The routes module docstring says newsletter preview/read boundaries are here, and that migration and activation stay disabled.

Read routes return series configuration, paginated editions, single-edition detail, publication history, publication-operation events, and period rollups. Write routes adopt a series, change lifecycle, refresh edition inputs, approve revisions, cancel editions, attest publication operations, and preview or update schedules and lifecycle transitions. Several mutating handlers call require_console_write_trust before work proceeds. Handlers that call _require_schema raise HTTP 503 when schema_available is false; history and event reads use has_history_schema, and newsletter_series returns available: false without 503.

Routes

All paths are relative to /api/marketing.

MethodPathPermissionHandlerWhat it does
GET/campaigns/{campaign_key}/newslettermarketing.readnewsletter_seriesReturns newsletter availability flags. With the schema present, generation and effects flags come from newsletter_generation_enabled and from newsletter_effects_enabled and marketing_publication_effects_enabled; with it absent, both flags are false. Optional series row plus schedule policy, and observed_at.
PUT/campaigns/{campaign_key}/newslettermarketing.writesave_newsletter_seriesRequires write trust and verified schema; adopts a newsletter series for the campaign via adopt_series.
POST/campaigns/{campaign_key}/newsletter/lifecyclemarketing.writenewsletter_lifecycleRequires write trust and schema; resolves series for campaign, then applies change_lifecycle with app generation setting.
GET/campaigns/{campaign_key}/editionsmarketing.readnewsletter_editionsRequires schema; returns paginated editions via editions_page (limit, optional cursor query params).
GET/editions/{edition_key}marketing.readnewsletter_editionRequires schema; returns edition detail via read_edition.
GET/campaigns/{campaign_key}/publication-historymarketing.readnewsletter_publication_historyRequires shared publication history schema; paginated history via history_page.
POST/editions/{edition_key}/inputs/refreshmarketing.writenewsletter_refresh_inputsRequires write trust and schema; tenant-gated daily report capture, then returns manifest key and refreshed edition.
POST/editions/{edition_key}/revisions/approvemarketing.writenewsletter_approve_revisionRequires write trust and schema; calls approve_revision.
GET/publication-operations/{operation_key}/eventsmarketing.readnewsletter_publication_eventsRequires shared publication history schema; paginated events via events_page.
POST/editions/{edition_key}/cancelmarketing.writenewsletter_cancel_editionRequires write trust and schema; cancels edition via cancel_edition.
POST/publication-operations/{operation_key}/attestmarketing.writenewsletter_attest_publicationRequires write trust and schema; attests operation via attest_operation, JSON body fields from request model.
GET/campaigns/{campaign_key}/newsletter/periodmarketing.readnewsletter_periodRequires schema; period rollup via period_rollup (since, until query params).
POST/campaigns/{campaign_key}/newsletter/schedule/previewmarketing.writenewsletter_preview_scheduleRequires write trust; schedule preview via preview_schedule after resolving series key.
PUT/campaigns/{campaign_key}/newsletter/schedulemarketing.writenewsletter_update_scheduleRequires write trust; schedule update via update_schedule.
POST/campaigns/{campaign_key}/newsletter/lifecycle/previewmarketing.writenewsletter_preview_lifecycleRequires write trust; lifecycle preview via lifecycle_preview on an open DB connection.

Request and response models

Handlers declare JSON request bodies where noted. Types are imported from recox.marketing_newsletter_contracts except where domain code in this repo shows additional fields.

Request bodies

ModelUsed onFields evidenced in module code
AdoptSeriesPUT /campaigns/{campaign_key}/newsletteradopt_series uses expected_version, idempotency_key, project_key, owner, and policy on AdoptSeries
PreviewedLifecyclePOST .../newsletter/lifecyclePassed to change_lifecycle as lifecycle command; domain reads idempotency_key, expected_version, action, optional preview_hash
LifecycleCommandPOST .../newsletter/lifecycle/previewThe preview route passes LifecycleCommand to lifecycle_preview; change_lifecycle reads idempotency_key, expected_version, and action, and reads preview_hash only when that attribute is present
VersionedCommandPOST /editions/{edition_key}/inputs/refreshexpected_version, idempotency_key (passed to capture_inputs)
ApproveRevisionPOST /editions/{edition_key}/revisions/approveBody type only; forwarded to approve_revision
CancelEditionPOST /editions/{edition_key}/cancelidempotency_key, expected_version, reason
AttestPublicationPOST /publication-operations/{operation_key}/attestexpected_version, edition_revision_key, statement, evidence_ref, idempotency_key
SchedulePreviewPOST .../newsletter/schedule/previewBody type only; forwarded to preview_schedule
ScheduleUpdatePUT /campaigns/{campaign_key}/newsletter/scheduleBody type only; forwarded to update_schedule

SchedulePolicy (nested under adoption and schedule domain logic) includes at least: destination_account, planned_disposition, resume_missing, recovery_from, recovery_through, eligibility_time, deadline_offset_days, provider_mode, as validated in domain lifecycle and edition code.

Query parameters

RouteParameters
newsletter_editions, newsletter_publication_history, newsletter_publication_eventslimit (int, default 25), cursor (str | None)
newsletter_periodsince (str), until (str)

Response shapes (where defined in handlers or domain)

HandlerResponse
newsletter_seriesdict with available, migration_applied, generation_enabled, effects_enabled, series (row dict plus policy when present, or None), observed_at
save_newsletter_seriesadopt_series result: series_key, version, lifecycle
newsletter_lifecyclechange_lifecycle result: series_key, version, lifecycle
newsletter_refresh_inputsmanifest_key (str), edition (read_edition dict)
newsletter_cancel_editionedition_key, version, canceled (true)
newsletter_attest_publicationJSON object from attest_operation Pydantic model_dump(mode='json')
Paginated reads (editions, publication-history, events)dict from respective query helpers
newsletter_editiondict from read_edition
newsletter_perioddict from period_rollup
Schedule and lifecycle preview/updatedict from control helpers

Behaviour and errors

Schema and availability

  • _require_schema() connects to the app database and, when schema_available is false, raises 503 with detail.code newsletter_schema_unverified and a message that migrations are held pending verification.
  • newsletter_series does not call _require_schema on the hot path; if schema is missing it returns available: false and disables flags without 503.
  • newsletter_publication_history and newsletter_publication_events require has_history_schema; otherwise 503 with detail Shared publication schema is not verified/applied.

Trust and tenant gates

Mutating routes listed in the route table call require_console_write_trust(request) first (schedule preview/update and lifecycle preview included; they do not call _require_schema in the handler body).

newsletter_refresh_inputs returns 404 with detail Daily AI reports are not available for this company when app.settings.tenant != 'recohut'. It also returns 404 Edition not found when the edition row is absent.

Domain errors mapped to HTTP

Exception / conditionStatusTypical detail
Missing campaign (series GET)404Campaign not found
Missing series for campaign404Series not found
LookupError from domain/query helpers404str(exc)
NewsletterConflict409str(exc)
PublicationTransitionError (attest)409str(exc)
ValueError422str(exc)

Representative domain conflict messages include idempotency mismatch, series already exists, campaign or series version drift, activation disabled pending verification, pending publication blocking cancel, and lifecycle preview hash mismatch when preview_hash is supplied.

Idempotency and versioning

Write paths that accept idempotency_key and expected_version defer to domain command recording (marketing_newsletter_command) for replay and optimistic concurrency, as implemented in adopt_series, change_lifecycle, cancel_edition, and capture_inputs.

How the permission model applies

Console route permissions are declared in route_roles.py. Each handler name maps to a permission string; gate refuses signed-in users whose role lacks that permission (403 with a denied error object). Unlisted endpoints also yield 403. The table is a ceiling: capabilities and handlers may narrow access further but not widen it.

For this module, read handlers require marketing.read and write handlers require marketing.write. When sign-in is off, route role checks follow the console boundary behaviour described in the permission module docstring (OS admin context).

Permissions for all fifteen handlers in this module are listed in ROUTE_PERMISSIONS under the marketing_newsletter_routes.* keys matching handler function names.

How is this page?

Last updated on