Common examples

Copy-paste recipes for the things most teams wire up first. Each one is a complete request; swap in your own API key and recipients.

Every example assumes an environment API key in $MESSY_API_KEY and at least one connected integration for the channel. If you have not done that yet, start with the Quickstart.

Send a transactional email with a template

Keep copy out of your code. Save a template with the trigger name order_confirmed, write the body in Liquid, then reference it by trigger and pass the values in data.

template body
<h1>Thanks, {{ name }}</h1>
<p>Order {{ order_number }} totalling {{ total }} is on its way.</p>
<a href="{{ unsubscribe_url }}">Unsubscribe</a>

Then trigger it. The template decides the channel, subject and body, so the request only carries the recipient and the variables:

order-confirmed.sh
curl https://api.messy.sh/messages/trigger \
  -H "Authorization: Bearer $MESSY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "trigger": "order_confirmed",
    "to": "ada@example.com",
    "data": {
      "name": "Ada",
      "order_number": "1024",
      "total": "€42.00"
    }
  }'
unsubscribe_url is generated per message and injected for you, so you never build one by hand. Any value you pass under that key is overwritten.

Send a one-off transactional email

When the content is genuinely dynamic and a template would only get in the way, post the body inline:

welcome.sh
curl https://api.messy.sh/messages \
  -H "Authorization: Bearer $MESSY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "email",
    "to": "ada@example.com",
    "subject": "Welcome to Acme",
    "body": "<h1>You are in</h1><p>Thanks for signing up.</p>"
  }'

Send an SMS one-time passcode

OTPs, magic links and password resets are detected as security-sensitive and excluded from click tracking automatically, so the code never routes through a tracking domain.

otp.sh
curl https://api.messy.sh/messages \
  -H "Authorization: Bearer $MESSY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "type": "sms", "to": "+15551234567", "body": "Your Acme code is 481920" }'

Email several recipients at once

Each to, cc and bcc recipient is evaluated by your delivery rules independently. One request can deliver to some recipients and be rejected for others, and each outcome is recorded on its own child message.

cc.sh
curl https://api.messy.sh/messages \
  -H "Authorization: Bearer $MESSY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "email",
    "to": "ada@acme.com",
    "cc": "billing@acme.com",
    "bcc": "audit@acme.com",
    "subject": "Invoice 1024",
    "body": "<p>Your invoice is attached.</p>"
  }'

Keep staging traffic out of real inboxes

Delivery rules are configured in the dashboard rather than with an API key. Two steps, once per environment:

  • On Integrations, switch the staging environment’s email channel to block by default.
  • On Automations, add one rule with the condition @acme.com and the outcome Deliver.

A condition is a plain substring of the recipient, so @acme.com is all you need. Anything it does not match falls through to the channel default and comes back with a rejected status instead of reaching a provider. See Delivery rules for the full evaluation order.

Check what happened

Every send returns a message id and a status. Poll or list them to see where a message ended up:

status.sh
curl "https://api.messy.sh/messages?channel=email&status=rejected" \
  -H "Authorization: Bearer $MESSY_API_KEY"

pending is queued, sent and delivered are success, failed is a provider error, rejected means a rule blocked it, and suppressed means the recipient is unsubscribed from that channel.