Shared

Render a live email preview of a draft campaign

post/api/marketing/campaigns/{id}/preview

A server round trip, DELIBERATELY not a zero-round-trip client-side render the way TemplateStudio.tsx's own preview works: {{booking_url}} resolves through appBaseUrl() (booking/manage.ts), which reads a server-only environment variable Next.js never inlines into a client bundle. Draft fields are read from the REQUEST BODY, never the saved row, since the point is previewing what the operator has typed but not yet autosaved. Renders against a fixed sample customer name, the same "real renderer against a sample" approach TemplateStudio.tsx uses for its own booking preview.

Authorization

sessionCookie
sb-qxrvgfkjyvbngipqvslu-auth-token<token>

The dashboard's Supabase Auth session cookie, set at sign-in. Large sessions are split across numbered chunks (…auth-token.0, .1), so treat this as a cookie family rather than one name.

Every request re-validates it against the Auth server (getUser()), never by decoding the cookie locally: a JWT nothing has checked is not a credential. Tenancy is then read from the verified app_metadata.company_id claim and enforced by row-level security; it is never read from request input, on any route, ever.

role (admin / staff) is deliberately not in RLS. It gates specific actions in route code, the operations marked admin below, so hiding a button in the UI is cosmetic only, and a route's own check is the enforcement.

In: cookie

Path Parameters

id*string

Campaign id (unused by the handler; the rendered company comes from the caller's own session).

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/api/marketing/campaigns/string/preview" \  -H "Content-Type: application/json" \  -d '{}'
{  "subject": "string",  "html": "string"}