Skip to main content
Instead of hardcoding values, you can use placeholders that AutoSend replaces with actual data when sending the email via API. For example:
When the email is sent, it becomes:
Variables make your emails more personalized, relevant, and engaging, all without manually editing each message.

How Variables Work

When you send a transactional email through the AutoSend Email API, you can include variables as key-value pairs in your request payload. AutoSend automatically replaces these placeholders with their corresponding values in the email template before delivery.

Example API Payload:

Example Template:

Resulting Email:


Supported Variable Syntax

AutoSend uses double curly braces {{variable_name}} to identify variables inside email templates.
Variable names can include letters, numbers, and underscores, but must start with a letter (e.g., {{ first_name }}, {{ orderTotal }}).

Using Variables in Email Templates

You can use variables anywhere in the email:
  • Subject line
  • Body text
  • Button URLs
  • Links or call-to-actions
Example:

Default and Custom Variables

Default Variables

Some system-level variables are automatically available when sending emails through AutoSend. For example:
  • {{email}} — recipient’s email address
  • {{date}} — current date

Custom Variables

You can define your own custom variables when sending emails via the API. These can be anything specific to your workflow. Eg. {{order_id}}, {{invoice_amount}}, or {{reset_link}}.

Nested Variables

AutoSend supports nested variables, allowing you to organize your data in a more structured way. You can access nested properties using dot notation in your templates. For example, instead of flat variables like {{firstName}}, you can use nested structures like {{userData.firstName}} or {{order.id}}.

Example API Payload with Nested Data:

Example Template with Nested Variables:

Resulting Email:

Nested variables are only available with transactional emails. They are not supported in email campaigns or automation emails.

Default Values

Not every recipient will have a value for every variable. You can use the pipe operator (|) to provide a default value that renders when the variable is missing.

What this does:

  • If firstName is Johan → Hello Johan!
  • If firstName is missing or empty → Hello there!
The default value is used when the variable is:
  • Not included in your API payload
  • null
  • An empty string
  • Only whitespace
Values like 0 or false are treated as real values and render as-is.

Rules for default values

  • Wrap the default in quotes. Both double quotes (") and single quotes (') work, and smart quotes added by rich-text editors are handled automatically.
  • Use one pipe per variable. Multiple pipes like {{ name | "a" | "b" }} are not supported.
  • Whitespace is flexible. {{firstName|"there"}} and {{ firstName | "there" }} behave the same.
An unquoted default is ignored. {{ firstName | there }} behaves like {{firstName}} and renders empty when the variable is missing. Always quote the default: {{ firstName | "there" }}.
Default values also work with nested variables:

Example:

You can use default values anywhere variables work: subject lines, body text, links, and call-to-actions. They are supported in transactional emails, campaigns, and automation emails.

Using Variables with Conditions

For richer conditional logic, such as showing or hiding entire blocks of content, you can use if/else in your email templates. For example, you can show a different message depending on whether a firstName is available.

What this does:

  • If firstName exists → Hello Johan!
  • If it’s missing/empty → Hello there!
This works for any variable in AutoSend. For a simple fallback value, the pipe operator shown above is the shorter option; use {{#if}}{{else}}{{/if}} when you need to switch larger pieces of content.

Best Practices

  • Always test your templates before sending live emails to ensure variables are replaced correctly.
  • Provide default values with the pipe operator in case a variable is missing (e.g., {{ name | "there" }} renders “there” if name is not provided).
  • Keep variable names descriptive for better clarity and maintainability.

Troubleshooting

  • Check that your variable name in the API payload exactly matches the placeholder in your template.
  • Ensure that the variable is passed under the "variables" object in your API request.
  • Preview the email in your AutoSend dashboard to confirm the replacement works as expected.
  • Make sure the default is wrapped in quotes: {{ firstName | "there" }}. An unquoted default is ignored.
  • Check that the variable is actually empty. Values like 0 or false count as real values and render instead of the default.
  • Use only one pipe per variable.