Unifies sending messages across push, email, and SMS

How to send a message

This guide will help you use the API effectively and assumes you've integrated our SDK into an Android, iOS, or Web app. If you do not intend to implement push in your messaging strategy, skip to next steps.

Craft a message

We'll send the message 'Hello, world' localized for Spanish, French, and Chinese.

// Message request body
{
  "contents": {
    "en": "Hello, world",
    "es": "Hola Mundo",
    "fr": "Bonjour le monde",
    "zh-Hans": "你好世界"
  }
}

Choose a targeting strategy

Choose one strategy for message targeting:

We'll target the "Subscribed Users" segment so we send to everyone.

// Message request body
{
  "contents": {
    "en": "Hello, world",
    "es": "Hola mundo",
    "fr": "Bonjour le monde",
    "zh-Hans": "你好世界"
  },
  "included_segments": ["Subscribed Users"]
}

Pick the delivery channel

Messages can be delivered across the following channels:

  • Mobile and Web Push Notifications ("push")
  • Email ("email")
  • SMS ("sms")

Let's set our target_channel as Push Notifications.

{
  "contents": {
    "en": "Hello, World",
    "es": "Hola Mundo",
    "fr": "Bonjour le monde",
    "zh-Hans": "你好世界"
  },
  "included_segments": ["Subscribed Users"],
  "target_channel": "push"
}

Each channel has channel-specific parameters that can be included in the request body. You can access the channel parameters page by clicking on any of the Read more... links inside each API doc's parameter descriptions.

Set the delivery schedule

You can specify rate limits and delivery timing as well. See Delivery Notification Parameters to learn more.

Submit the request

The final cURL request will send the message to All Subscribers in each recipient's local language.

curl -X "POST" "https://api.onesignal.com/notifications" \
     -H 'Content-Type: application/json' \
     -H 'Authorization: Basic MjAyYzJlOTAtMTY4Mi00ODFlLTg2MDYtZTM2YzllM2ZlZTVi' \
     -d $'{
  "target_channel": "push",
  "included_segments": [
    "Subscribed Users"
  ],
  "app_id": "202d4f61-1ca9-42df-9d36-bb17d8123abc",
  "contents": {
    "en": "Hello, world",
    "es": "Hola mundo",
    "fr": "Bonjour le monde",
    "zh-Hans": "你好世界"
  }
}'

Next steps

Head to the API doc for the channel you'd like to use.