Common use cases
Use transactional messages to:- Send login and verification codes (OTP)
- Confirm orders, receipts, or subscription changes
- Deliver billing status or renewal alerts
- Remind users about appointments or deadlines
- Acknowledge key actions (e.g. signups or purchases)
Requirements
Before sending transactional messages, we suggest reviewing the following guides:- Understand OneSignal Users, Subscriptions, and Aliases.
- Setup your Database, DMP, or CRM to communicate with OneSignal or use one of our Integrations.
- Create Templates to personalize your messages.
- Use Liquid Syntax to personalize your messages.
Identifying users
To target individual users, you must identify them within OneSignal. The recommended approach is to set an External ID, which should map to the user identifier used in your database or CRM. OneSignal also supports up to 20 aliases per user, enabling you to associate multiple identifiers (e.g.,other_user_id, facebook_id, etc.) across your systems. For email and SMS, you can also send messages directly using the email address or phone number respectively.
Targeting users
Use the Create Message API to send transactional messages across push, email, and SMS channels by targeting users via aliases, email addresses, phone numbers, or subscription IDs.Send to aliases (recommended)
Useinclude_aliases to target the recommended external_id or other aliases like so:
Send to subscriptions
If you want to send to specific Subscriptions, you can use theinclude_subscription_ids property. This option is not recommended because Users can have multiple Subscriptions.
Send to email addresses
If you have the user’s email address, you can send emails to them using theinclude_email_tokens property.
Any emails included that do not exist within your OneSignal app will automatically create a new email subscription.
Send to phone numbers
If you have the user’s phone number, you can send them SMS and MMS using theinclude_phone_numbers property.
Any phone numbers included that do not exist within your OneSignal app will automatically create a new SMS subscription.
Adding custom data
For personalized content, pass user-specificcustom_data to the message using Templates and Liquid syntax.
Steps to add custom data:
- Create a Template via the dashboard or Create template API.
- Add Liquid Variables (e.g.,
{{ message.custom_data.order_id }}) to your template. - Reference the
template_idandcustom_datawithin your Create Message API call.
Example: One-Time Passcode (OTP)
- Identify the user using an alias, email, or phone number.
- Create a Template that includes a verification code:
- Generate the
verification_codeon your server when the user requests access. - Input the
verification_codevalue into the API request.
custom_data you can input the variable value directly into the message with string concatenation. For example:
Troubleshooting
- For
include_aliases, the alias must be registered on the user beforehand. - For email/SMS, ensure correct formatting.