Generate Emails
Generated Emails
Generate Emails
Two discriminated actions — synchronously resolve %variables% across the outbox, or queue an AI generation task for a single node.
POST
Generate Emails
CLI:
Overview
One POST, two actions, discriminated by theaction field in the body:
resolve— synchronously resolves%variables%for every non-AI sendable node across every lead and upsertscampaign_prospect_messagesrows asdraft. Also copies pre-generated AI examples onto matching leads (matched by lead name). Manually-edited rows are preserved; template changes flow through to unedited rows.generate_ai— queues thegenerate-ai-messagesTrigger.dev task for a specific AI node. ChargesAI_MESSAGE_GENERATIONcredits per lead after the task is queued. The pre-flight credit check returns 402 without destroying any existing messages.
draft status.
AI agent notes
resolve is safe to re-run. It upserts on (campaign_id, prospect_id, node_id) and excludes manually-edited rows from the upsert — template changes propagate without clobbering user customizations. If the “find edited messages” query itself fails, the server falls back to ignoreDuplicates: true for the whole batch to avoid silently overwriting edits.AI seeding matches on lead name. When resolve seeds AI drafts from generated_examples, it normalizes first_name + last_name and matches against leads. Duplicate names yield multiple rows (one per lead); unmatched examples are logged and skipped. After adding new leads or regenerating the skeleton, re-run resolve to pick up the new matches.generate_ai credit flow. Credits are previewed before any write — a 402 response means no existing messages were deleted and no task was queued. Credits are only charged AFTER the task is successfully enqueued. For single-lead regeneration (prospect_ids provided), the server deletes the existing draft for that (node, lead) pair first so the task can produce a fresh version.Related endpoints. For reading the draft outbox or inline-editing a single message, see GET and PATCH on the same path. For building the framework before calling resolve, see generateCampaignContent.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Campaign UUID
Body
application/json
- Option 1
- Option 2
Discriminated by action. resolve synchronously re-aggregates draft messages; generate_ai fires a background task and returns immediately.
Available options:
resolve Response
Messages were resolved or AI generation was queued.
- Option 1
- Option 2