Create templates for push, email and sms visible and usable in the dashboard and API.

Overview

Use this endpoint to create a new message template in the OneSignal app. It will be made available to use through sending messages on the dashboard and via the API using the template id parameter.


How to use this API

First make sure the channel (push, email, SMS) is setup in the app. See Channel Setup for details.

Push templates

Requirements:

Set the contents property with the English (en) language. See Push Notification Content for details.

All Push Channel Properties are valid to include in your push templates.

By default, all push platforms are enabled (set to true). You can disable specific push platforms by only setting the ones you want enabled to true. For example, setting isAndroid: true will make iOS and Web platforms disabled in the template. See Platforms to delivery To for details.

Email templates

Requirements:

Set isEmail: true.

Must include the email_subject and email_body properties.

When creating a template to send to email users, all Email Channel Properties are valid to include in your email templates.

SMS templates

Requirements:

Set isSMS: true.

When creating a template to send to SMS users, all SMS Channel Properties are valid to include in your SMS templates.


Examples

Create a push template

curl --location 'https://api.onesignal.com/templates' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "app_id": "<APP ID>",
    "name":"push example",
    "contents": {
        "en": "English Message"
    }       
}'

Create an email template

curl --location 'https://api.onesignal.com/templates' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "app_id":"<APP ID>",
    "name":"email example",
    "isEmail": true,
    "email_subject":"English Subject",
    "email_body":"English Message"
}'

Create an SMS template

curl --location 'https://api.onesignal.com/templates' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
    "app_id":"<APP ID>",
    "name":"email example",
    "isSMS": true,
    "sms_from":"+1234567890",
    "contents": { 
    	"en": "English Message" 
     },
    "sms_media_urls": ["https://cat.com/cat.jpg"],
}'

Body parameters

All channel parameters are available for Push Notification, Email, and SMS templates. Below are the required parameters depending on the channel in which you are creating the template.

contents

Type object

Channel Push notifications, SMS

Description

Required with en language for push notification and SMS templates. Specifies the content shown to the end user for push and SMS templates.

If used for push, all Push Notification parameters may be used in the body of this request.

If used for SMS, make sure to include isSMS set to true. Otherwise, omit this parameter for push templates.

isSMS

Type boolean

Channel SMS

Description

Specifies the channel for the template as SMS.

Set this value to true if the intended usage for the template is to send to SMS users.

If this value is set to true, all SMS channel properties may be used in the body of this request.

isEmail

Type boolean

Channel Email

Description

Required along with email_subject and email_body for email templates.

Set this value to true if the intended usage for the template is to send to email users.

If this value is set to true, all email channel properties may be used in the body of this request.

email_subject

Type string

Channel Email

Description

The subject line of the email. Required if isEmail is set to true

email_body

Type string

Channel Email

Description

Specifies the body of the email being sent. Required if isEmail is set to true

Language