curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/activities/activity/{activity_type} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"event": "start",
"activity_id": "<string>",
"event_attributes": {},
"event_updates": {},
"name": "<string>",
"contents": {
"en": "<string>"
},
"headings": {
"en": "<string>"
},
"include_aliases": {
"external_id": [
"<string>"
]
},
"include_subscription_ids": [
"<string>"
],
"included_segments": [
"<string>"
],
"excluded_segments": [
"<string>"
],
"filters": [
{
"field": "first_session",
"relation": ">",
"value": "1",
"key": "<string>"
}
],
"stale_date": 123,
"ios_sound": "<string>",
"ios_relevance_score": 123,
"idempotency_key": "<string>"
}
'import Onesignal from '@onesignal/node-onesignal';
const configuration = Onesignal.createConfiguration({
restApiKey: 'YOUR_REST_API_KEY',
});
const apiInstance = new Onesignal.DefaultApi(configuration);
// string | Your OneSignal App ID in UUID v4 format.
const appId: string = "YOUR_APP_ID";
// string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app\'s Live Activity implementation.
const activityType: string = "order_status";
// StartLiveActivityRequest
const startLiveActivityRequest: Onesignal.StartLiveActivityRequest = {
name: "name_example",
event: "start",
activity_id: "activity_id_example",
event_attributes: {},
event_updates: {},
contents: {
en: "en_example",
ar: "ar_example",
bs: "bs_example",
bg: "bg_example",
ca: "ca_example",
zh_hans: "zh_hans_example",
zh_hant: "zh_hant_example",
zh: "zh_example",
hr: "hr_example",
cs: "cs_example",
da: "da_example",
nl: "nl_example",
et: "et_example",
fi: "fi_example",
fr: "fr_example",
ka: "ka_example",
de: "de_example",
el: "el_example",
hi: "hi_example",
he: "he_example",
hu: "hu_example",
id: "id_example",
it: "it_example",
ja: "ja_example",
ko: "ko_example",
lv: "lv_example",
lt: "lt_example",
ms: "ms_example",
nb: "nb_example",
pl: "pl_example",
fa: "fa_example",
pt: "pt_example",
pa: "pa_example",
ro: "ro_example",
ru: "ru_example",
sr: "sr_example",
sk: "sk_example",
es: "es_example",
sv: "sv_example",
th: "th_example",
tr: "tr_example",
uk: "uk_example",
vi: "vi_example",
},
headings: {
en: "en_example",
ar: "ar_example",
bs: "bs_example",
bg: "bg_example",
ca: "ca_example",
zh_hans: "zh_hans_example",
zh_hant: "zh_hant_example",
zh: "zh_example",
hr: "hr_example",
cs: "cs_example",
da: "da_example",
nl: "nl_example",
et: "et_example",
fi: "fi_example",
fr: "fr_example",
ka: "ka_example",
de: "de_example",
el: "el_example",
hi: "hi_example",
he: "he_example",
hu: "hu_example",
id: "id_example",
it: "it_example",
ja: "ja_example",
ko: "ko_example",
lv: "lv_example",
lt: "lt_example",
ms: "ms_example",
nb: "nb_example",
pl: "pl_example",
fa: "fa_example",
pt: "pt_example",
pa: "pa_example",
ro: "ro_example",
ru: "ru_example",
sr: "sr_example",
sk: "sk_example",
es: "es_example",
sv: "sv_example",
th: "th_example",
tr: "tr_example",
uk: "uk_example",
vi: "vi_example",
},
stale_date: 1,
priority: 1,
ios_relevance_score: 3.14,
idempotency_key: "idempotency_key_example",
include_aliases: {
"key": [
"key_example",
],
},
include_subscription_ids: [
"include_subscription_ids_example",
],
included_segments: [
"included_segments_example",
],
excluded_segments: [
"excluded_segments_example",
],
filters: [
{
field: "tag",
key: "level",
value: "10",
hours_ago: "24",
radius: 3.14,
lat: 3.14,
long: 3.14,
relation: ">",
},
],
};
try {
const response = await apiInstance.startLiveActivity(appId, activityType, startLiveActivityRequest);
console.log(response);
} catch (e) {
if (e instanceof Onesignal.ApiException) {
// `e.errorMessages` flattens any error-envelope shape to a `string[]`;
// the raw parsed body remains on `e.body`.
console.error("startLiveActivity failed: HTTP " + e.code, e.errorMessages);
} else {
throw e;
}
}import onesignal
from onesignal.api import default_api
from onesignal.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
# Some of the OneSignal endpoints require ORGANIZATION_API_KEY token for authorization, while others require REST_API_KEY.
# We recommend adding both of them in the configuration page so that you will not need to figure it out yourself.
configuration = onesignal.Configuration(
rest_api_key = "YOUR_REST_API_KEY", # App REST API key required for most endpoints
organization_api_key = "YOUR_ORGANIZATION_API_KEY" # Organization key is only required for creating new apps and other top-level endpoints
)
# Enter a context with an instance of the API client
with onesignal.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = default_api.DefaultApi(api_client)
app_id = "YOUR_APP_ID" # Your OneSignal App ID in UUID v4 format.
activity_type = "order_status" # The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
start_live_activity_request = StartLiveActivityRequest(
name="name_example",
event="start",
activity_id="activity_id_example",
event_attributes={},
event_updates={},
contents=LanguageStringMap(
en="en_example",
ar="ar_example",
bs="bs_example",
bg="bg_example",
ca="ca_example",
zh_hans="zh_hans_example",
zh_hant="zh_hant_example",
zh="zh_example",
hr="hr_example",
cs="cs_example",
da="da_example",
nl="nl_example",
et="et_example",
fi="fi_example",
fr="fr_example",
ka="ka_example",
de="de_example",
el="el_example",
hi="hi_example",
he="he_example",
hu="hu_example",
id="id_example",
it="it_example",
ja="ja_example",
ko="ko_example",
lv="lv_example",
lt="lt_example",
ms="ms_example",
nb="nb_example",
pl="pl_example",
fa="fa_example",
pt="pt_example",
pa="pa_example",
ro="ro_example",
ru="ru_example",
sr="sr_example",
sk="sk_example",
es="es_example",
sv="sv_example",
th="th_example",
tr="tr_example",
uk="uk_example",
vi="vi_example",
),
headings=LanguageStringMap(
en="en_example",
ar="ar_example",
bs="bs_example",
bg="bg_example",
ca="ca_example",
zh_hans="zh_hans_example",
zh_hant="zh_hant_example",
zh="zh_example",
hr="hr_example",
cs="cs_example",
da="da_example",
nl="nl_example",
et="et_example",
fi="fi_example",
fr="fr_example",
ka="ka_example",
de="de_example",
el="el_example",
hi="hi_example",
he="he_example",
hu="hu_example",
id="id_example",
it="it_example",
ja="ja_example",
ko="ko_example",
lv="lv_example",
lt="lt_example",
ms="ms_example",
nb="nb_example",
pl="pl_example",
fa="fa_example",
pt="pt_example",
pa="pa_example",
ro="ro_example",
ru="ru_example",
sr="sr_example",
sk="sk_example",
es="es_example",
sv="sv_example",
th="th_example",
tr="tr_example",
uk="uk_example",
vi="vi_example",
),
stale_date=1,
priority=1,
ios_relevance_score=3.14,
idempotency_key="idempotency_key_example",
include_aliases=IncludeAliases(
key=[
"key_example",
],
),
include_subscription_ids=[
"include_subscription_ids_example",
],
included_segments=[
"included_segments_example",
],
excluded_segments=[
"excluded_segments_example",
],
filters=[
Filter(
field="tag",
key="level",
value="10",
hours_ago="24",
radius=3.14,
lat=3.14,
long=3.14,
relation=">",
),
],
)
try:
# Start Live Activity
api_response = api_instance.start_live_activity(app_id, activity_type, start_live_activity_request)
pprint(api_response)
except onesignal.ApiException as e:
print("Exception when calling DefaultApi->start_live_activity: %s\n" % e)
print("Status Code: %s" % e.status)
print("Response Body: %s" % e.body)<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: rest_api_key
$config = onesignal\client\Configuration::getDefaultConfiguration()
->setRestApiKeyToken('YOUR_REST_API_KEY')
->setOrganizationApiKeyToken('YOUR_ORGANIZATION_API_KEY');
$apiInstance = new onesignal\client\Api\DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$app_id = 'YOUR_APP_ID'; // string | Your OneSignal App ID in UUID v4 format.
$activity_type = 'order_status'; // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
$start_live_activity_request = new \onesignal\client\model\StartLiveActivityRequest(); // \onesignal\client\model\StartLiveActivityRequest
try {
$result = $apiInstance->startLiveActivity($app_id, $activity_type, $start_live_activity_request);
print_r($result);
} catch (\onesignal\client\ApiException $e) {
echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL;
echo 'Status Code: ', $e->getCode(), PHP_EOL;
// getErrorMessages() flattens any error-envelope shape to a string[];
// the raw body remains on getResponseBody().
echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL;
echo 'Response Body: ', $e->getResponseBody(), PHP_EOL;
} catch (\Exception $e) {
echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL;
}package main
import (
"context"
"fmt"
"os"
"github.com/OneSignal/onesignal-go-api/v5"
)
func main() {
appId := "YOUR_APP_ID" // string | Your OneSignal App ID in UUID v4 format.
activityType := "order_status" // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
startLiveActivityRequest := *onesignal.NewStartLiveActivityRequest("Name_example", "Event_example", "ActivityId_example", map[string]interface{}{"key": "value"}, map[string]interface{}{"key": "value"}, *onesignal.NewLanguageStringMap(), *onesignal.NewLanguageStringMap()) // StartLiveActivityRequest |
configuration := onesignal.NewConfiguration()
apiClient := onesignal.NewAPIClient(configuration)
restAuth := context.WithValue(context.Background(), onesignal.RestApiKey, "YOUR_REST_API_KEY") // App REST API key required for most endpoints
resp, r, err := apiClient.DefaultApi.StartLiveActivity(restAuth, appId, activityType).StartLiveActivityRequest(startLiveActivityRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.StartLiveActivity``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
if apiErr, ok := err.(*onesignal.GenericOpenAPIError); ok {
// ErrorMessages() flattens any error-envelope shape to a []string;
// the raw body remains on Body().
fmt.Fprintf(os.Stderr, "Error Messages: %v\n", apiErr.ErrorMessages())
fmt.Fprintf(os.Stderr, "Response Body: %s\n", apiErr.Body())
}
}
// response from `StartLiveActivity`: StartLiveActivitySuccessResponse
fmt.Fprintf(os.Stdout, "Response from `DefaultApi.StartLiveActivity`: %v\n", resp)
}require 'onesignal'
# setup authorization
OneSignal.configure do |config|
# Configure Bearer authorization: rest_api_key
config.rest_api_key = 'YOUR_REST_API_KEY'
end
api_instance = OneSignal::DefaultApi.new
app_id = 'YOUR_APP_ID' # String | Your OneSignal App ID in UUID v4 format.
activity_type = 'order_status' # String | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
start_live_activity_request = OneSignal::StartLiveActivityRequest.new({name: 'name_example', event: 'start', activity_id: 'activity_id_example', event_attributes: 3.56, event_updates: 3.56, contents: OneSignal::LanguageStringMap.new, headings: OneSignal::LanguageStringMap.new}) # StartLiveActivityRequest |
begin
# Start Live Activity
result = api_instance.start_live_activity(app_id, activity_type, start_live_activity_request)
p result
rescue OneSignal::ApiError => e
puts "Error when calling DefaultApi->start_live_activity: #{e}"
puts "Status Code: #{e.code}"
# `e.error_messages` flattens any error-envelope shape to an Array<String>;
# the raw body remains on `e.response_body`.
puts "Error Messages: #{e.error_messages}"
puts "Response Body: #{e.response_body}"
end// Import classes:
import com.onesignal.client.ApiClient;
import com.onesignal.client.ApiException;
import com.onesignal.client.Configuration;
import com.onesignal.client.auth.*;
import com.onesignal.client.model.*;
import com.onesignal.client.api.DefaultApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.onesignal.com");
// Configure HTTP bearer authorization: rest_api_key
HttpBearerAuth rest_api_key = (HttpBearerAuth) defaultClient.getAuthentication("rest_api_key");
rest_api_key.setBearerToken("YOUR_REST_API_KEY");
DefaultApi apiInstance = new DefaultApi(defaultClient);
String appId = "YOUR_APP_ID"; // String | Your OneSignal App ID in UUID v4 format.
String activityType = "order_status"; // String | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
StartLiveActivityRequest startLiveActivityRequest = new StartLiveActivityRequest(); // StartLiveActivityRequest |
try {
StartLiveActivitySuccessResponse result = apiInstance.startLiveActivity(appId, activityType, startLiveActivityRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#startLiveActivity");
System.err.println("Status code: " + e.getCode());
// getErrorMessages() flattens any error-envelope shape to a List<String>;
// the raw body remains on getResponseBody().
System.err.println("Error messages: " + e.getErrorMessages());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}using System;
using System.Collections.Generic;
using System.Diagnostics;
using OneSignalApi.Api;
using OneSignalApi.Client;
using OneSignalApi.Model;
namespace Example
{
public class StartLiveActivityExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "https://api.onesignal.com";
// Configure Bearer token for authorization: rest_api_key
config.AccessToken = "YOUR_REST_API_KEY";
var apiInstance = new DefaultApi(config);
var appId = "YOUR_APP_ID"; // string | Your OneSignal App ID in UUID v4 format.
var activityType = "order_status"; // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
var startLiveActivityRequest = new StartLiveActivityRequest(); // StartLiveActivityRequest |
try
{
// Start Live Activity
StartLiveActivitySuccessResponse result = apiInstance.StartLiveActivity(appId, activityType, startLiveActivityRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.StartLiveActivity: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
// e.ErrorMessages flattens any error-envelope shape to an IReadOnlyList<string>;
// the raw body remains on e.ErrorContent.
Debug.Print("Error Messages: " + string.Join(", ", e.ErrorMessages));
Debug.Print("Response Body: " + e.ErrorContent);
Debug.Print(e.StackTrace);
}
}
}
}use onesignal_rust_api::apis::configuration::Configuration;
use onesignal_rust_api::apis::default_api;
use onesignal_rust_api::models;
#[tokio::main]
async fn main() {
let mut configuration = Configuration::new();
configuration.rest_api_key_token = Some("YOUR_REST_API_KEY".to_string());
// Realistic values are pulled from the spec's `example:` fields where present.
let app_id: &str = "YOUR_APP_ID";
let activity_type: &str = "order_status";
let start_live_activity_request: models::StartLiveActivityRequest = todo!();
match default_api::start_live_activity(&configuration, app_id, activity_type, start_live_activity_request).await {
Ok(resp) => println!("{:?}", resp),
Err(e @ onesignal_rust_api::apis::Error::ResponseError(_)) => {
// `e.error_messages()` flattens any error-envelope shape to a Vec<String>;
// the raw response remains on the ResponseError variant.
eprintln!("start_live_activity failed: {:?}", e.error_messages());
}
Err(e) => eprintln!("start_live_activity failed: {:?}", e),
}
}{
"notification_id": "<string>"
}{
"errors": [
"Reason for the message not being started. Usually due to the activity type not being found in the app."
]
}{
"errors": [
"API rate limit exceeded"
]
}{
"errors": [
"Service temporarily unavailable"
]
}Start Live Activity
Remotely start an iOS Live Activity with the OneSignal REST API, also known as push-to-start. Covers required body fields, choosing an activity_id, and audience targeting.
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/activities/activity/{activity_type} \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"event": "start",
"activity_id": "<string>",
"event_attributes": {},
"event_updates": {},
"name": "<string>",
"contents": {
"en": "<string>"
},
"headings": {
"en": "<string>"
},
"include_aliases": {
"external_id": [
"<string>"
]
},
"include_subscription_ids": [
"<string>"
],
"included_segments": [
"<string>"
],
"excluded_segments": [
"<string>"
],
"filters": [
{
"field": "first_session",
"relation": ">",
"value": "1",
"key": "<string>"
}
],
"stale_date": 123,
"ios_sound": "<string>",
"ios_relevance_score": 123,
"idempotency_key": "<string>"
}
'import Onesignal from '@onesignal/node-onesignal';
const configuration = Onesignal.createConfiguration({
restApiKey: 'YOUR_REST_API_KEY',
});
const apiInstance = new Onesignal.DefaultApi(configuration);
// string | Your OneSignal App ID in UUID v4 format.
const appId: string = "YOUR_APP_ID";
// string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app\'s Live Activity implementation.
const activityType: string = "order_status";
// StartLiveActivityRequest
const startLiveActivityRequest: Onesignal.StartLiveActivityRequest = {
name: "name_example",
event: "start",
activity_id: "activity_id_example",
event_attributes: {},
event_updates: {},
contents: {
en: "en_example",
ar: "ar_example",
bs: "bs_example",
bg: "bg_example",
ca: "ca_example",
zh_hans: "zh_hans_example",
zh_hant: "zh_hant_example",
zh: "zh_example",
hr: "hr_example",
cs: "cs_example",
da: "da_example",
nl: "nl_example",
et: "et_example",
fi: "fi_example",
fr: "fr_example",
ka: "ka_example",
de: "de_example",
el: "el_example",
hi: "hi_example",
he: "he_example",
hu: "hu_example",
id: "id_example",
it: "it_example",
ja: "ja_example",
ko: "ko_example",
lv: "lv_example",
lt: "lt_example",
ms: "ms_example",
nb: "nb_example",
pl: "pl_example",
fa: "fa_example",
pt: "pt_example",
pa: "pa_example",
ro: "ro_example",
ru: "ru_example",
sr: "sr_example",
sk: "sk_example",
es: "es_example",
sv: "sv_example",
th: "th_example",
tr: "tr_example",
uk: "uk_example",
vi: "vi_example",
},
headings: {
en: "en_example",
ar: "ar_example",
bs: "bs_example",
bg: "bg_example",
ca: "ca_example",
zh_hans: "zh_hans_example",
zh_hant: "zh_hant_example",
zh: "zh_example",
hr: "hr_example",
cs: "cs_example",
da: "da_example",
nl: "nl_example",
et: "et_example",
fi: "fi_example",
fr: "fr_example",
ka: "ka_example",
de: "de_example",
el: "el_example",
hi: "hi_example",
he: "he_example",
hu: "hu_example",
id: "id_example",
it: "it_example",
ja: "ja_example",
ko: "ko_example",
lv: "lv_example",
lt: "lt_example",
ms: "ms_example",
nb: "nb_example",
pl: "pl_example",
fa: "fa_example",
pt: "pt_example",
pa: "pa_example",
ro: "ro_example",
ru: "ru_example",
sr: "sr_example",
sk: "sk_example",
es: "es_example",
sv: "sv_example",
th: "th_example",
tr: "tr_example",
uk: "uk_example",
vi: "vi_example",
},
stale_date: 1,
priority: 1,
ios_relevance_score: 3.14,
idempotency_key: "idempotency_key_example",
include_aliases: {
"key": [
"key_example",
],
},
include_subscription_ids: [
"include_subscription_ids_example",
],
included_segments: [
"included_segments_example",
],
excluded_segments: [
"excluded_segments_example",
],
filters: [
{
field: "tag",
key: "level",
value: "10",
hours_ago: "24",
radius: 3.14,
lat: 3.14,
long: 3.14,
relation: ">",
},
],
};
try {
const response = await apiInstance.startLiveActivity(appId, activityType, startLiveActivityRequest);
console.log(response);
} catch (e) {
if (e instanceof Onesignal.ApiException) {
// `e.errorMessages` flattens any error-envelope shape to a `string[]`;
// the raw parsed body remains on `e.body`.
console.error("startLiveActivity failed: HTTP " + e.code, e.errorMessages);
} else {
throw e;
}
}import onesignal
from onesignal.api import default_api
from onesignal.models import *
from pprint import pprint
# See configuration.py for a list of all supported configuration parameters.
# Some of the OneSignal endpoints require ORGANIZATION_API_KEY token for authorization, while others require REST_API_KEY.
# We recommend adding both of them in the configuration page so that you will not need to figure it out yourself.
configuration = onesignal.Configuration(
rest_api_key = "YOUR_REST_API_KEY", # App REST API key required for most endpoints
organization_api_key = "YOUR_ORGANIZATION_API_KEY" # Organization key is only required for creating new apps and other top-level endpoints
)
# Enter a context with an instance of the API client
with onesignal.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = default_api.DefaultApi(api_client)
app_id = "YOUR_APP_ID" # Your OneSignal App ID in UUID v4 format.
activity_type = "order_status" # The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
start_live_activity_request = StartLiveActivityRequest(
name="name_example",
event="start",
activity_id="activity_id_example",
event_attributes={},
event_updates={},
contents=LanguageStringMap(
en="en_example",
ar="ar_example",
bs="bs_example",
bg="bg_example",
ca="ca_example",
zh_hans="zh_hans_example",
zh_hant="zh_hant_example",
zh="zh_example",
hr="hr_example",
cs="cs_example",
da="da_example",
nl="nl_example",
et="et_example",
fi="fi_example",
fr="fr_example",
ka="ka_example",
de="de_example",
el="el_example",
hi="hi_example",
he="he_example",
hu="hu_example",
id="id_example",
it="it_example",
ja="ja_example",
ko="ko_example",
lv="lv_example",
lt="lt_example",
ms="ms_example",
nb="nb_example",
pl="pl_example",
fa="fa_example",
pt="pt_example",
pa="pa_example",
ro="ro_example",
ru="ru_example",
sr="sr_example",
sk="sk_example",
es="es_example",
sv="sv_example",
th="th_example",
tr="tr_example",
uk="uk_example",
vi="vi_example",
),
headings=LanguageStringMap(
en="en_example",
ar="ar_example",
bs="bs_example",
bg="bg_example",
ca="ca_example",
zh_hans="zh_hans_example",
zh_hant="zh_hant_example",
zh="zh_example",
hr="hr_example",
cs="cs_example",
da="da_example",
nl="nl_example",
et="et_example",
fi="fi_example",
fr="fr_example",
ka="ka_example",
de="de_example",
el="el_example",
hi="hi_example",
he="he_example",
hu="hu_example",
id="id_example",
it="it_example",
ja="ja_example",
ko="ko_example",
lv="lv_example",
lt="lt_example",
ms="ms_example",
nb="nb_example",
pl="pl_example",
fa="fa_example",
pt="pt_example",
pa="pa_example",
ro="ro_example",
ru="ru_example",
sr="sr_example",
sk="sk_example",
es="es_example",
sv="sv_example",
th="th_example",
tr="tr_example",
uk="uk_example",
vi="vi_example",
),
stale_date=1,
priority=1,
ios_relevance_score=3.14,
idempotency_key="idempotency_key_example",
include_aliases=IncludeAliases(
key=[
"key_example",
],
),
include_subscription_ids=[
"include_subscription_ids_example",
],
included_segments=[
"included_segments_example",
],
excluded_segments=[
"excluded_segments_example",
],
filters=[
Filter(
field="tag",
key="level",
value="10",
hours_ago="24",
radius=3.14,
lat=3.14,
long=3.14,
relation=">",
),
],
)
try:
# Start Live Activity
api_response = api_instance.start_live_activity(app_id, activity_type, start_live_activity_request)
pprint(api_response)
except onesignal.ApiException as e:
print("Exception when calling DefaultApi->start_live_activity: %s\n" % e)
print("Status Code: %s" % e.status)
print("Response Body: %s" % e.body)<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: rest_api_key
$config = onesignal\client\Configuration::getDefaultConfiguration()
->setRestApiKeyToken('YOUR_REST_API_KEY')
->setOrganizationApiKeyToken('YOUR_ORGANIZATION_API_KEY');
$apiInstance = new onesignal\client\Api\DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$app_id = 'YOUR_APP_ID'; // string | Your OneSignal App ID in UUID v4 format.
$activity_type = 'order_status'; // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
$start_live_activity_request = new \onesignal\client\model\StartLiveActivityRequest(); // \onesignal\client\model\StartLiveActivityRequest
try {
$result = $apiInstance->startLiveActivity($app_id, $activity_type, $start_live_activity_request);
print_r($result);
} catch (\onesignal\client\ApiException $e) {
echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL;
echo 'Status Code: ', $e->getCode(), PHP_EOL;
// getErrorMessages() flattens any error-envelope shape to a string[];
// the raw body remains on getResponseBody().
echo 'Error Messages: ', implode(', ', $e->getErrorMessages()), PHP_EOL;
echo 'Response Body: ', $e->getResponseBody(), PHP_EOL;
} catch (\Exception $e) {
echo 'Exception when calling DefaultApi->startLiveActivity: ', $e->getMessage(), PHP_EOL;
}package main
import (
"context"
"fmt"
"os"
"github.com/OneSignal/onesignal-go-api/v5"
)
func main() {
appId := "YOUR_APP_ID" // string | Your OneSignal App ID in UUID v4 format.
activityType := "order_status" // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
startLiveActivityRequest := *onesignal.NewStartLiveActivityRequest("Name_example", "Event_example", "ActivityId_example", map[string]interface{}{"key": "value"}, map[string]interface{}{"key": "value"}, *onesignal.NewLanguageStringMap(), *onesignal.NewLanguageStringMap()) // StartLiveActivityRequest |
configuration := onesignal.NewConfiguration()
apiClient := onesignal.NewAPIClient(configuration)
restAuth := context.WithValue(context.Background(), onesignal.RestApiKey, "YOUR_REST_API_KEY") // App REST API key required for most endpoints
resp, r, err := apiClient.DefaultApi.StartLiveActivity(restAuth, appId, activityType).StartLiveActivityRequest(startLiveActivityRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.StartLiveActivity``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
if apiErr, ok := err.(*onesignal.GenericOpenAPIError); ok {
// ErrorMessages() flattens any error-envelope shape to a []string;
// the raw body remains on Body().
fmt.Fprintf(os.Stderr, "Error Messages: %v\n", apiErr.ErrorMessages())
fmt.Fprintf(os.Stderr, "Response Body: %s\n", apiErr.Body())
}
}
// response from `StartLiveActivity`: StartLiveActivitySuccessResponse
fmt.Fprintf(os.Stdout, "Response from `DefaultApi.StartLiveActivity`: %v\n", resp)
}require 'onesignal'
# setup authorization
OneSignal.configure do |config|
# Configure Bearer authorization: rest_api_key
config.rest_api_key = 'YOUR_REST_API_KEY'
end
api_instance = OneSignal::DefaultApi.new
app_id = 'YOUR_APP_ID' # String | Your OneSignal App ID in UUID v4 format.
activity_type = 'order_status' # String | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
start_live_activity_request = OneSignal::StartLiveActivityRequest.new({name: 'name_example', event: 'start', activity_id: 'activity_id_example', event_attributes: 3.56, event_updates: 3.56, contents: OneSignal::LanguageStringMap.new, headings: OneSignal::LanguageStringMap.new}) # StartLiveActivityRequest |
begin
# Start Live Activity
result = api_instance.start_live_activity(app_id, activity_type, start_live_activity_request)
p result
rescue OneSignal::ApiError => e
puts "Error when calling DefaultApi->start_live_activity: #{e}"
puts "Status Code: #{e.code}"
# `e.error_messages` flattens any error-envelope shape to an Array<String>;
# the raw body remains on `e.response_body`.
puts "Error Messages: #{e.error_messages}"
puts "Response Body: #{e.response_body}"
end// Import classes:
import com.onesignal.client.ApiClient;
import com.onesignal.client.ApiException;
import com.onesignal.client.Configuration;
import com.onesignal.client.auth.*;
import com.onesignal.client.model.*;
import com.onesignal.client.api.DefaultApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.onesignal.com");
// Configure HTTP bearer authorization: rest_api_key
HttpBearerAuth rest_api_key = (HttpBearerAuth) defaultClient.getAuthentication("rest_api_key");
rest_api_key.setBearerToken("YOUR_REST_API_KEY");
DefaultApi apiInstance = new DefaultApi(defaultClient);
String appId = "YOUR_APP_ID"; // String | Your OneSignal App ID in UUID v4 format.
String activityType = "order_status"; // String | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
StartLiveActivityRequest startLiveActivityRequest = new StartLiveActivityRequest(); // StartLiveActivityRequest |
try {
StartLiveActivitySuccessResponse result = apiInstance.startLiveActivity(appId, activityType, startLiveActivityRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#startLiveActivity");
System.err.println("Status code: " + e.getCode());
// getErrorMessages() flattens any error-envelope shape to a List<String>;
// the raw body remains on getResponseBody().
System.err.println("Error messages: " + e.getErrorMessages());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}using System;
using System.Collections.Generic;
using System.Diagnostics;
using OneSignalApi.Api;
using OneSignalApi.Client;
using OneSignalApi.Model;
namespace Example
{
public class StartLiveActivityExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "https://api.onesignal.com";
// Configure Bearer token for authorization: rest_api_key
config.AccessToken = "YOUR_REST_API_KEY";
var apiInstance = new DefaultApi(config);
var appId = "YOUR_APP_ID"; // string | Your OneSignal App ID in UUID v4 format.
var activityType = "order_status"; // string | The name of the Live Activity defined in your app. This should match the attributes struct used in your app's Live Activity implementation.
var startLiveActivityRequest = new StartLiveActivityRequest(); // StartLiveActivityRequest |
try
{
// Start Live Activity
StartLiveActivitySuccessResponse result = apiInstance.StartLiveActivity(appId, activityType, startLiveActivityRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.StartLiveActivity: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
// e.ErrorMessages flattens any error-envelope shape to an IReadOnlyList<string>;
// the raw body remains on e.ErrorContent.
Debug.Print("Error Messages: " + string.Join(", ", e.ErrorMessages));
Debug.Print("Response Body: " + e.ErrorContent);
Debug.Print(e.StackTrace);
}
}
}
}use onesignal_rust_api::apis::configuration::Configuration;
use onesignal_rust_api::apis::default_api;
use onesignal_rust_api::models;
#[tokio::main]
async fn main() {
let mut configuration = Configuration::new();
configuration.rest_api_key_token = Some("YOUR_REST_API_KEY".to_string());
// Realistic values are pulled from the spec's `example:` fields where present.
let app_id: &str = "YOUR_APP_ID";
let activity_type: &str = "order_status";
let start_live_activity_request: models::StartLiveActivityRequest = todo!();
match default_api::start_live_activity(&configuration, app_id, activity_type, start_live_activity_request).await {
Ok(resp) => println!("{:?}", resp),
Err(e @ onesignal_rust_api::apis::Error::ResponseError(_)) => {
// `e.error_messages()` flattens any error-envelope shape to a Vec<String>;
// the raw response remains on the ResponseError variant.
eprintln!("start_live_activity failed: {:?}", e.error_messages());
}
Err(e) => eprintln!("start_live_activity failed: {:?}", e),
}
}{
"notification_id": "<string>"
}{
"errors": [
"Reason for the message not being started. Usually due to the activity type not being found in the app."
]
}{
"errors": [
"API rate limit exceeded"
]
}{
"errors": [
"Service temporarily unavailable"
]
}Overview
Remotely start an iOS Live Activity using OneSignal’s REST API. Live Activities provide real-time updates directly on the Lock Screen and Dynamic Island (on supported devices), enhancing user engagement with ongoing events like sports games, deliveries, or countdowns. Before using this API, ensure your app is properly configured by following the Live Activities developer setup. Starting a Live Activity remotely requires iOS 17.2 or newer and OneSignal iOS SDK 5.2.0 or newer. On iOS 16.1 through 17.1, start Live Activities in-app instead.How to use this API
Set the activity type in the URL
activity_type to the name of the Live Activity attributes struct in your widget extension, such as OneSignalWidgetAttributes. The value is case-sensitive and must match your struct name exactly, or the request finds no recipients.Set the required body fields
event: The action to perform. This endpoint only supportsstart.activity_id: The identifier you use later to update or end the activity. See Choose an activity ID.event_attributes: The static data that initializes the activity. See Set event attributes.event_updates: The dynamic data the activity displays. See Set event updates.name: An internal label for the message, up to 128 characters. Recipients never see it.contents: The push message body, withenat minimum.headings: The push title, withenat minimum.
contents and headings. On the Update Live Activity API, contents is optional and headings is not available.Choose your target audience
included_segments. Without one, the request has no recipients. See Choose your target audience.Set optional delivery parameters
stale_date to the Unix timestamp when the content becomes outdated, which lets your widget show a fallback message. Set ios_relevance_score to order multiple activities in the Dynamic Island.Set priority to 5 to deliver opportunistically without spending Apple’s high-priority budget, or 10 to deliver immediately at the cost of budget. When you omit priority, OneSignal sends 10. See Update frequency and throttling.This endpoint has no dismissal_date parameter. You set the dismissal time when you end the activity with the Update Live Activity API.Choose an activity ID
Theactivity_id is a topic key, not a per-message identifier. Every device registered under the same activity_id receives the same updates, so one Update Live Activity request fans out to all of them. Save the value you choose, because you need it to update or end the activity later.
Pick the pattern that matches your use case:
- Shared topic: many users follow the same real-world event, such as a live game, election results, a flight status, or a service incident. Use one stable business identifier for all of them, such as
game-1234. A single update request then reaches every subscriber. Avoid random IDs here, since they would force you to update each device’s activity separately. - Per entity: each user follows their own activity, such as a food delivery, a ride, or an order. Give every activity its own identifier. A UUID, CUID, or NanoID works well, as does a namespaced business ID like
order-98765.
activity_id across users. Because the activity_id is the fan-out key, every device registered under it receives the same content. Reusing a generic value like order-tracking for all orders would show one user’s delivery ETA on another user’s Lock Screen.{
"activity_id": "217aae2b-42ee-4097-bc3f-b7a6e9d15b9b",
...
}
Choose your target audience
Before sending a message, you need to determine who should receive it. OneSignal offers three targeting options:- Aliases & Subscription IDs: Send messages to specific users using unique identifiers such as External ID (recommended), OneSignal ID, custom alias, or subscription ID.
- Segments: Target predefined user groups based on attributes and behavior.
- Filters: Create custom targeting rules using user properties, such as tags, location, or activity.
Set event attributes to initialize the Live Activity
Set default/static data to display in the Live Activity upon start. The object must match theAttributes struct defined in your widget extension, excluding the ContentState and onesignal properties.
{
"event_attributes": {
"awayTeam": "Away Team Name",
"homeTeam": "Home Team Name"
}
}
Set event updates for dynamic content
The content used to update a running Live Activity. The object must match theContentState struct defined within your app’s Live Activity. See Live Activities developer setup.
Ensure that the event_updates object matches the ContentState struct exactly as defined in your Live Activity implementation. Inconsistencies can cause Live Activities to fail to display.
Date-typed field in your custom Attributes or ContentState struct as a Unix timestamp in seconds, not as an ISO 8601 string and not in milliseconds. ActivityKit decodes date values in the push payload as seconds since 1970, and your app cannot change that strategy. To avoid the ambiguity, declare the field as a Double of Unix seconds and convert it in your widget. OneSignal’s stale_date and dismissal_date parameters are also Unix timestamps in seconds.{
"event_updates": {
"quarter": 1,
"homeScore": 70,
"awayScore": 78,
"inTimeout": false
}
}
FAQ
What is the difference between event_attributes and event_updates?
event_attributes is static data set once when the activity starts, matching your Attributes struct. event_updates is dynamic data matching your ContentState struct, and it is the only part you can change later with the Update Live Activity API.
Can one request start the same Live Activity for many users?
Yes. Target a segment or a list of aliases, and give every recipient the sameactivity_id when they should all see identical content, such as a live sports score. Each recipient gets their own activity on device, but a single update request then reaches all of them. Use distinct IDs when the content is specific to each user, such as an order status.
Why did my request return no recipients?
Theactivity_type in the URL must exactly match the name of your attributes struct, including casing, and your targeting must resolve to at least one subscribed device running iOS 17.2 or newer with OneSignal iOS SDK 5.2.0 or newer. See Troubleshooting: No recipients for the full checklist.
Can I set a dismissal time when starting the activity?
No. This endpoint has nodismissal_date parameter. Set dismissal_date when you end the activity with the Update Live Activity API. If you end an activity without one, iOS keeps it on the Lock Screen for up to 4 hours.Headers
Your App API key with prefix Key . See Keys & IDs.
Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
The name of the Live Activity defined in your app. This should match the your-nameAttributes struct used in your app code. See Live Activities developer setup. Example: If your app defines a Live Activity as OneSignalWidgetAttributes, then activity_type should be OneSignalWidgetAttributes.
Body
The action to perform on the Live Activity. This request only supports start.
start The topic key for this Live Activity. Every device that starts an activity with this value receives the same updates, so one Update Live Activity request fans out to all of them. Use one shared value when many users follow the same event, such as game-1234 for a live match. Use a distinct value per user when the content is specific to that user, such as order-98765 for one delivery. Never reuse a per-user value across users, or one user's content appears on every other user's device. Save the value, because updating or ending the activity requires it. See Choose an activity ID.
The static data to initialize the Live Activity. See Live Activities developer setup.
The content used to update a running Live Activity. The object must conform to the ContentState interface defined within your app's Live Activity. See Live Activities developer setup.
An internal name you set to help organize and track messages. Not shown to recipients. Maximum 128 characters.
The push message body with language-specific values.
Show child attributes
Show child attributes
The push title with language-specific values.
Show child attributes
Show child attributes
Target up to 20,000 users by their external_id, onesignal_id, or your own custom alias. Use with target_channel to control the delivery channel. Not compatible with any other targeting parameters like filters, include_subscription_ids, included_segments, or excluded_segments. See Sending messages with the OneSignal API.
Show child attributes
Show child attributes
Target users' specific subscriptions by ID. Include up to 20,000 subscription_id per API call. Not compatible with any other targeting parameters like filters, include_aliases, included_segments, or excluded_segments. See Sending messages with the OneSignal API.
Target predefined Segments. Users that are in multiple segments will only be sent the message once. Can be combined with excluded_segments. Not compatible with any other targeting parameters like filters, include_aliases, or include_subscription_ids. See Sending messages with the OneSignal API.
Exclude users in predefined Segments. Overrides membership in any segment specified in the included_segments. Not compatible with any other targeting parameters like filters, include_aliases, or include_subscription_ids. See Sending messages with the OneSignal API.
Dynamically target users based on properties like tags, activity, or location using flexible AND/OR logic. Limited to 200 total entries, including fields and OR operators. Not compatible with other targeting parameters like include_aliases, include_subscription_ids, included_segments, or excluded_segments. See Sending messages with the OneSignal API.
Show child attributes
Show child attributes
A Unix timestamp (in seconds) that indicates the date the Live Activity is considered outdated. Once this time is reached, the system updates the Live Activity to ActivityState.stale at which point you can update the Live Activity to indicate that its content is out of date.
Set the urgency of this start request. 10 delivers immediately and counts against the budget Apple imposes per device for high-priority Live Activity updates. 5 delivers opportunistically and does not count against the budget. When you omit this parameter, OneSignal sends 10. Apple recommends you try 5 first and reserve 10 for updates that need the user's immediate attention. If your app needs frequent high-priority updates, add the NSSupportsLiveActivitiesFrequentUpdates key to your Info.plist. See Update frequency and throttling.
5, 10 The name of a sound file in your app bundle, including its extension (for example, explode_sound.wav), to play when this message is delivered. Omit this field to deliver it silently. See Notification sounds.
A value between 0 and 1. If you start more than one Live Activity for your app, the Live Activity with the highest relevance score appears in the Dynamic Island. If Live Activities have the same relevance score, the system displays the Live Activity that started first. Additionally, the Relevance Score determines the order of your Live Activities on the Lock Screen.
A unique identifier used to prevent duplicate messages from repeat API calls. See Idempotent notification requests. Any RFC 9562 UUID supported. Valid for 30 days. Previously called external_id.
Response
201
The ID of the Live Activity that was created in UUID v4 format.
Was this page helpful?