Create in-app message
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/in_app_messages \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"is_draft": false,
"in_app_message": {
"name": "Welcome offer",
"display_duration": 0,
"html": "<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>",
"start_time": "2026-11-01T00:00:00Z",
"included_segment_ids": [
"YOUR_SEGMENT_ID"
],
"triggers": [
{
"conditions": [
{
"kind": "session_time",
"operator": "greater",
"value": 30
}
]
}
]
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
is_draft: false,
in_app_message: {
name: 'Welcome offer',
display_duration: 0,
html: '<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>',
start_time: '2026-11-01T00:00:00Z',
included_segment_ids: ['YOUR_SEGMENT_ID'],
triggers: [{conditions: [{kind: 'session_time', operator: 'greater', value: 30}]}]
}
})
};
fetch('https://api.onesignal.com/apps/{app_id}/in_app_messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/in_app_messages"
payload = {
"is_draft": False,
"in_app_message": {
"name": "Welcome offer",
"display_duration": 0,
"html": "<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>",
"start_time": "2026-11-01T00:00:00Z",
"included_segment_ids": ["YOUR_SEGMENT_ID"],
"triggers": [{ "conditions": [
{
"kind": "session_time",
"operator": "greater",
"value": 30
}
] }]
}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/in_app_messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'is_draft' => false,
'in_app_message' => [
'name' => 'Welcome offer',
'display_duration' => 0,
'html' => '<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>',
'start_time' => '2026-11-01T00:00:00Z',
'included_segment_ids' => [
'YOUR_SEGMENT_ID'
],
'triggers' => [
[
'conditions' => [
[
'kind' => 'session_time',
'operator' => 'greater',
'value' => 30
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/in_app_messages"
payload := strings.NewReader("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/in_app_messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.post("https://api.onesignal.com/apps/{app_id}/in_app_messages")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/in_app_messages");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
request.AddJsonBody("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"success": true,
"payload": {
"id": "2c5c6b7e-0f6d-4a5e-9a2b-1a2b3c4d5e6f"
}
}{
"success": false,
"errors": [
"'name' Message name required",
"'body' Display duration is required"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"errors": [
"Current user permissions do not allow this action."
]
}{
"errors": [
"API rate limit exceeded"
],
"limit": "API Per App"
}Create in-app message
Create a custom HTML in-app message with a schedule, audience, and triggers. It can be set as a draft or published right away. The in-app message is shown full screen, without margin, and your HTML controls how it looks.
POST
/
apps
/
{app_id}
/
in_app_messages
Create in-app message
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/in_app_messages \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"is_draft": false,
"in_app_message": {
"name": "Welcome offer",
"display_duration": 0,
"html": "<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>",
"start_time": "2026-11-01T00:00:00Z",
"included_segment_ids": [
"YOUR_SEGMENT_ID"
],
"triggers": [
{
"conditions": [
{
"kind": "session_time",
"operator": "greater",
"value": 30
}
]
}
]
}
}
'const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': '<content-type>'},
body: JSON.stringify({
is_draft: false,
in_app_message: {
name: 'Welcome offer',
display_duration: 0,
html: '<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>',
start_time: '2026-11-01T00:00:00Z',
included_segment_ids: ['YOUR_SEGMENT_ID'],
triggers: [{conditions: [{kind: 'session_time', operator: 'greater', value: 30}]}]
}
})
};
fetch('https://api.onesignal.com/apps/{app_id}/in_app_messages', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/in_app_messages"
payload = {
"is_draft": False,
"in_app_message": {
"name": "Welcome offer",
"display_duration": 0,
"html": "<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>",
"start_time": "2026-11-01T00:00:00Z",
"included_segment_ids": ["YOUR_SEGMENT_ID"],
"triggers": [{ "conditions": [
{
"kind": "session_time",
"operator": "greater",
"value": 30
}
] }]
}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/in_app_messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'is_draft' => false,
'in_app_message' => [
'name' => 'Welcome offer',
'display_duration' => 0,
'html' => '<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>',
'start_time' => '2026-11-01T00:00:00Z',
'included_segment_ids' => [
'YOUR_SEGMENT_ID'
],
'triggers' => [
[
'conditions' => [
[
'kind' => 'session_time',
'operator' => 'greater',
'value' => 30
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: <content-type>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/in_app_messages"
payload := strings.NewReader("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "<content-type>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/in_app_messages")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = '<content-type>'
request.body = "{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}"
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.post("https://api.onesignal.com/apps/{app_id}/in_app_messages")
.header("Authorization", "<authorization>")
.header("Content-Type", "<content-type>")
.body("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/in_app_messages");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
request.AddJsonBody("{\n \"is_draft\": false,\n \"in_app_message\": {\n \"name\": \"Welcome offer\",\n \"display_duration\": 0,\n \"html\": \"<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>\",\n \"start_time\": \"2026-11-01T00:00:00Z\",\n \"included_segment_ids\": [\n \"YOUR_SEGMENT_ID\"\n ],\n \"triggers\": [\n {\n \"conditions\": [\n {\n \"kind\": \"session_time\",\n \"operator\": \"greater\",\n \"value\": 30\n }\n ]\n }\n ]\n }\n}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"success": true,
"payload": {
"id": "2c5c6b7e-0f6d-4a5e-9a2b-1a2b3c4d5e6f"
}
}{
"success": false,
"errors": [
"'name' Message name required",
"'body' Display duration is required"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"errors": [
"Current user permissions do not allow this action."
]
}{
"errors": [
"API rate limit exceeded"
],
"limit": "API Per App"
}Overview
Create a custom HTML in-app message. Block editor style in-app messages and carousels can only be created from the dashboard. The API manages an in-app message’s default language only. Language variants cannot be created or edited through the API. See Design in-app messages with HTML for how to write the HTML and the in-app message JavaScript API for click handling.Every in-app message this API creates is shown full screen with no margin. Placement is not configurable through the API, though you can build a modal-style layout in your HTML.
How to use this API
Authenticate with your App API Key. The body has two top-level keys:is_draft and in_app_message. Inside in_app_message, only name, display_duration, and html are required.
{
"is_draft": false,
"in_app_message": {
"name": "Welcome offer",
"display_duration": 0,
"html": "<!doctype html><html><body><h1>Welcome!</h1><p>20% off your first order.</p></body></html>",
"start_time": "2026-11-01T00:00:00Z",
"included_segment_ids": ["YOUR_SEGMENT_ID"],
"triggers": [
{ "conditions": [{ "kind": "session_time", "operator": "greater", "value": 30 }] }
]
}
}
Draft or publish
is_draft is required and decides whether the in-app message goes live.
is_draft: truesaves the in-app message paused. Publish it later with Update in-app message or Pause or resume in-app message.is_draft: falsepublishes the in-app message. It starts displaying atstart_time, which defaults to now.
Send
is_draft at the top level of the body, beside in_app_message. A missing key, null, or an is_draft nested inside in_app_message is rejected with a 400 and nothing is created.Permissions
An API key can create and publish in-app messages in its app. A request made with an OAuth access token, such as through the OneSignal MCP server, acts with the role of the signed-in user. A role that can create in-app messages but cannot activate them, such as Composer, can create drafts only. That role receives a403 for is_draft: false.
Schedule and audience
start_timeandend_timeare ISO 8601 timestamps.start_timedefaults to now andend_timedefaults to no end.end_timecannot be beforestart_time.included_segment_idslists the Segments the in-app message is shown to.excluded_segment_idslists the Segments the in-app message is never shown to. Every ID must be a Segment of this app.display_durationis the number of seconds the in-app message stays on screen.0keeps the in-app message until the user dismisses it.
Triggers
triggers is an array of trigger sets. A set fires when all of its conditions hold. The in-app message shows when any set fires. Omit triggers or send [] to show the in-app message on app open. See In-app message triggers for how triggers behave on the device.
{
"triggers": [
{
"conditions": [
{ "kind": "session_time", "operator": "greater", "value": 30 },
{ "kind": "custom", "property": "plan", "operator": "equal", "value": "trial" }
]
}
]
}
| Field | Type | Description |
|---|---|---|
kind | string | custom, session_time, or min_time_since. |
property | string | The trigger key your app sets through the SDK. Required for custom. Omit for the time kinds. |
operator | string | greater, less, greater_or_equal, less_or_equal, equal, not_equal, exists, or not_exists. |
value | string or integer | The value to compare against. Its type depends on kind. |
| Kind | value | Rules |
|---|---|---|
custom | string | Compared against the trigger value your app sets. Required for every operator except exists and not_exists. Must be numeric for greater, less, greater_or_equal, and less_or_equal. |
session_time | integer | Seconds since the current session started. Always required. 1 to 2147483647. |
min_time_since | integer | Seconds since the last in-app message was shown. Always required. 1 to 2147483647. |
Redisplay
An in-app message is shown once per user by default. To show it again, sendredisplay_delay and redisplay_limit together. Sending one without the other is rejected.
redisplay_limitis the maximum number of re-showings per user. It must be at least1.2147483647means unlimited.redisplay_delayis the number of seconds between showings. It must be at least1.0is accepted only with aredisplay_limitof2147483647, which shows the in-app message every time its triggers are satisfied.
Limits
| Limit | Maximum | At the limit |
|---|---|---|
| Trigger sets per in-app message | 30 | The request is rejected with a 400 and nothing is saved. |
| Conditions per trigger set | 30 | The request is rejected with a 400 and nothing is saved. |
| Clickable elements in the HTML | 20 distinct data-onesignal-unique-label values | The request is rejected with a 400 and nothing is saved. |
Response
A successful request returns200 OK with the id of the new in-app message:
{
"success": true,
"payload": { "id": "2c5c6b7e-0f6d-4a5e-9a2b-1a2b3c4d5e6f" }
}
Headers
Your App API key with prefix Key. See Keys & IDs.
Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
Body
application/json
Was this page helpful?