Docs API Reference

POST /execute

Execute a flow to render and optionally send an email.

Overview

The /execute endpoint runs the flow configured for a template. Depending on your flow configuration, this can:

  • Render the template and return HTML (callback output)
  • Validate inputs and send via your configured provider (provider output)

Endpoint

POST /v1/execute

Request Body

FieldTypeRequiredDescription
templateIdstringYesThe template to execute
variablesobjectYesVariables to hydrate the template
_tostringConditionalRecipient email (required for provider output)
_subjectstringNoOverride the template subject
_replyTostringNoReply-to email address
_ccstringNoCC recipients (comma-separated)
_bccstringNoBCC recipients (comma-separated)

Fields prefixed with _ are reserved for email delivery configuration.

Example Request

curl -X POST https://api.mailsh.it/v1/execute \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": "tmpl_abc123",
    "variables": {
      "firstName": "Alice",
      "orderNumber": "12345"
    },
    "_to": "alice@example.com",
    "_subject": "Your order has shipped!"
  }'

Response Types

The response depends on your flow configuration.

Sent (Provider Output)

When the flow includes a provider output node and the email is sent successfully:

{
  "success": true,
  "type": "sent",
  "messageId": "msg_abc123xyz"
}

Callback (No Provider)

When the flow uses a callback output or has no output node:

{
  "success": true,
  "type": "callback",
  "html": "<!DOCTYPE html><html>...</html>",
  "text": "Plain text version...",
  "subject": "Your order has shipped!"
}

Validation Failed

When a verification node fails:

{
  "success": false,
  "type": "validation_failed",
  "error": "Invalid email address",
  "field": "_to"
}

Send Failed

When the email provider returns an error:

{
  "success": false,
  "type": "send_failed",
  "error": "Recipient email is not verified"
}

Flow Error

When there’s a configuration issue:

{
  "success": false,
  "type": "flow_error",
  "error": "Template not found in flow graph"
}

Flow Node Types

Your flow can include these node types:

Node TypeDescription
TemplateThe email template to render
VariablesInputs connected to the template
Provider OutputSends via your email provider
Callback OutputReturns HTML without sending
VerificationValidates inputs before proceeding

Verification Types

If your flow includes verification nodes, they run before sending:

Email Domain Verification

Validates the _to address format and domain MX records.

Required Fields

Ensures specified variables are provided and non-empty.

Custom Regex

Validates a variable against a regular expression pattern.

Code Examples

JavaScript

async function sendWelcomeEmail(email: string, name: string) {
  const response = await fetch('https://api.mailsh.it/v1/execute', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.MAILSHIT_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      templateId: 'tmpl_welcome',
      variables: { name },
      _to: email,
    }),
  })

  const result = await response.json()

  if (result.success && result.type === 'sent') {
    console.log('Email sent:', result.messageId)
  } else if (!result.success) {
    console.error('Failed:', result.error)
  }

  return result
}

Python

def send_welcome_email(email: str, name: str):
    response = requests.post(
        'https://api.mailsh.it/v1/execute',
        headers={
            'Authorization': f'Bearer {api_key}',
            'Content-Type': 'application/json',
        },
        json={
            'templateId': 'tmpl_welcome',
            'variables': {'name': name},
            '_to': email,
        },
    )

    result = response.json()

    if result.get('success') and result.get('type') == 'sent':
        print(f"Email sent: {result['messageId']}")
    elif not result.get('success'):
        print(f"Failed: {result['error']}")

    return result

Best Practices

  1. Always check success - Don’t assume emails were sent
  2. Handle all response types - Your flow configuration determines the response
  3. Log messageIds - Useful for debugging delivery issues
  4. Use verification nodes - Catch invalid inputs before sending