Skip to main content
POST
/
api
/
email
/
prepare
Prepare email content using template or inference mode
curl --request POST \
  --url https://dev.exante.app/api/email/prepare \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "context_type": "<string>",
  "context_uid": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "subject": "<string>",
  "body_text": "<string>",
  "mode": "template",
  "prompt_hint": "<string>"
}
'
{
  "subject": "<string>",
  "body_text": "<string>",
  "body_html": "<string>",
  "mode": "<string>",
  "errors": [
    {
      "token": "{shipping_address}",
      "message": "Token '{shipping_address}' is not available for context_type 'invoice'."
    }
  ]
}
The prepare endpoint resolves dynamic content for outbound emails. It supports two modes that determine how the final subject and body are generated.

Modes

Template Mode (mode: "template")

In template mode, you provide subject and body_text containing dynamic field tokens (e.g., {invoice_number}, {client_name}). The endpoint resolves these tokens against the context entity and returns the fully rendered content. Required parameters:
  • subject - Email subject with optional dynamic tokens
  • body_text - Email body with optional dynamic tokens
  • context_type - The entity type (e.g., "invoice")
  • context_uid - UUID of the entity to resolve fields from
Example request:
{
  "mode": "template",
  "context_type": "invoice",
  "context_uid": "a1b2c3d4-...",
  "subject": "Payment reminder for Invoice {invoice_number}",
  "body_text": "Hi {client_name},\n\nThis is a reminder that Invoice {invoice_number} for {amount_due} is due on {due_date}.\n\nBest regards"
}
Example response:
{
  "subject": "Payment reminder for Invoice INV-2024-001",
  "body_text": "Hi Acme Corp,\n\nThis is a reminder that Invoice INV-2024-001 for $1,500.00 is due on March 15, 2024.\n\nBest regards",
  "body_html": "<html>...",
  "mode": "template",
  "errors": []
}

Inference Mode (mode: "inference")

In inference mode, the endpoint uses AI to generate the subject and body based on the context entity’s data. The full context (all available field values) is passed to the AI model, which then composes appropriate email content. How it works:
  1. The context entity is loaded (e.g., the invoice specified by context_uid)
  2. All available dynamic field values are extracted (invoice number, amounts, dates, client info, etc.)
  3. This context data is serialized and included in the AI prompt
  4. The AI generates a professional subject line and body text based on the context
  5. You can guide the AI’s output using prompt_hint
Key distinction: In inference mode, you do NOT include {tokens} in your input. Instead, the resolved context data is automatically provided to the AI. The AI sees the actual values (e.g., “Invoice INV-2024-001”, “$1,500.00”) and composes the email accordingly. Parameters:
  • context_type - The entity type (e.g., "invoice")
  • context_uid - UUID of the entity whose data informs the AI
  • prompt_hint (optional) - Additional guidance for the AI (e.g., “friendly tone”, “focus on urgency”, “mention late fee policy”)
  • subject / body_text (optional) - Fallback content if inference fails
Example request:
{
  "mode": "inference",
  "context_type": "invoice",
  "context_uid": "a1b2c3d4-...",
  "prompt_hint": "Polite but firm tone, mention this is a final reminder before escalation"
}
Example response:
{
  "subject": "Final Reminder: Invoice INV-2024-001 Payment Overdue",
  "body_text": "Dear Acme Corp,\n\nI hope this message finds you well. I'm writing regarding Invoice INV-2024-001 for $1,500.00, which was due on March 15, 2024 and is now 10 days overdue.\n\nWe kindly request that you arrange payment at your earliest convenience. If payment is not received within the next 5 business days, we may need to escalate this matter.\n\nPlease let us know if you have any questions or concerns.\n\nBest regards",
  "body_html": "<html>...",
  "mode": "inference",
  "errors": []
}

Comparison

AspectTemplate ModeInference Mode
Content sourceYou provide the exact text with tokensAI generates the content
Dynamic fields{token} placeholders in your text are replacedContext data is passed to AI automatically
CustomizationFull control over wordingGuide via prompt_hint
Use caseStandardized templatesPersonalized, context-aware drafts

Available Dynamic Fields

Dynamic fields depend on the context_type. For invoice context:
TokenDescriptionExample Value
{invoice_number}Invoice identifierINV-2024-001
{issue_date}Date invoice was issuedJanuary 15, 2024
{due_date}Payment due dateFebruary 15, 2024
{amount_due}Outstanding amount$1,500.00
{total_cents}Total invoice amount$2,000.00
{days_overdue}Days past due date10
{client_name}Customer/client nameAcme Corp
{client_email}Customer emailbilling@acme.com
{payment_link}Link to payment portalhttps://pay.example.com/
{organization_name}Your organization nameMy Company LLC
{current_date}Today’s dateMarch 25, 2024
Use the List Dynamic Fields endpoint to get the complete list of available tokens for each context type.

Error Handling

The errors array contains any issues encountered during processing:
  • Template mode: Lists tokens that couldn’t be resolved (e.g., missing data)
  • Inference mode: Contains {inference} error if AI generation fails (falls back to provided subject/body_text)
{
  "errors": [
    {"token": "{payment_link}", "message": "No payment link configured for this invoice"}
  ]
}

HTML Generation

Both modes automatically generate body_html from the resolved/generated body_text. The HTML conversion supports:
  • **bold text**<strong>bold text</strong>
  • [Link Text]{https://example.com}<a href="https://example.com">Link Text</a>
  • [Link Text]{{example.com}}<a href="https://example.com">Link Text</a>
  • Bare URLs are auto-linked
  • Line breaks become <br> tags

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
context_type
string
required
context_uid
string<uuid>
required
subject
string
body_text
string
mode
enum<string>
Available options:
template,
inference
prompt_hint
string

Response

Prepared email content

subject
string
required
body_text
string
required
body_html
string
required
mode
string
required
errors
object[]
required