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
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}}.
Using Dynamic Variables with Conditions
You can use simpleif/else logic in your email templates to handle missing data. For example, if a user doesn’t have a firstName, you can fall back to a default like “there”.
What this does:
- If
firstNameexists →Hello Akash! - If it’s missing/empty →
Hello there!
{{#if}}{{else}}{{/if}} to make your messages feel natural even when some data is unavailable.
Best Practices
- Always test your templates before sending live emails to ensure variables are replaced correctly.
- Provide fallback values in your system in case a variable is missing (e.g., “Hi there” if
{{name}}is not provided). - Keep variable names descriptive for better clarity and maintainability.
Troubleshooting
If a variable doesn’t render correctly:
If a variable doesn’t render correctly:
- 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.