curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/live_activities/{activity_id}/notifications \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"event_updates": {},
"name": "<string>",
"stale_date": 123,
"dismissal_date": 123,
"ios_sound": "<string>",
"ios_relevance_score": 123
}
'import Onesignal from '@onesignal/node-onesignal';
const configuration = Onesignal.createConfiguration({
restApiKey: 'YOUR_REST_API_KEY',
});
const apiInstance = new Onesignal.DefaultApi(configuration);
// string | The OneSignal App ID for your app. Available in Keys & IDs.
const appId: string = "YOUR_APP_ID";
// string | Live Activity record ID
const activityId: string = "12345";
// UpdateLiveActivityRequest
const updateLiveActivityRequest: Onesignal.UpdateLiveActivityRequest = {
name: "name_example",
event: "update",
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",
},
sound: "sound_example",
ios_sound: "ios_sound_example",
stale_date: 1,
dismissal_date: 1,
priority: 1,
ios_relevance_score: 3.14,
};
try {
const response = await apiInstance.updateLiveActivity(appId, activityId, updateLiveActivityRequest);
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("updateLiveActivity 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" # The OneSignal App ID for your app. Available in Keys & IDs.
activity_id = "12345" # Live Activity record ID
update_live_activity_request = UpdateLiveActivityRequest(
name="name_example",
event="update",
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",
),
sound="sound_example",
ios_sound="ios_sound_example",
stale_date=1,
dismissal_date=1,
priority=1,
ios_relevance_score=3.14,
)
try:
# Update a Live Activity via Push
api_response = api_instance.update_live_activity(app_id, activity_id, update_live_activity_request)
pprint(api_response)
except onesignal.ApiException as e:
print("Exception when calling DefaultApi->update_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 | The OneSignal App ID for your app. Available in Keys & IDs.
$activity_id = '12345'; // string | Live Activity record ID
$update_live_activity_request = new \onesignal\client\model\UpdateLiveActivityRequest(); // \onesignal\client\model\UpdateLiveActivityRequest
try {
$result = $apiInstance->updateLiveActivity($app_id, $activity_id, $update_live_activity_request);
print_r($result);
} catch (\onesignal\client\ApiException $e) {
echo 'Exception when calling DefaultApi->updateLiveActivity: ', $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->updateLiveActivity: ', $e->getMessage(), PHP_EOL;
}package main
import (
"context"
"fmt"
"os"
"github.com/OneSignal/onesignal-go-api/v5"
)
func main() {
appId := "YOUR_APP_ID" // string | The OneSignal App ID for your app. Available in Keys & IDs.
activityId := "12345" // string | Live Activity record ID
updateLiveActivityRequest := *onesignal.NewUpdateLiveActivityRequest("Name_example", "Event_example", map[string]interface{}{"key": "value"}) // UpdateLiveActivityRequest |
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.UpdateLiveActivity(restAuth, appId, activityId).UpdateLiveActivityRequest(updateLiveActivityRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.UpdateLiveActivity``: %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 `UpdateLiveActivity`: UpdateLiveActivitySuccessResponse
fmt.Fprintf(os.Stdout, "Response from `DefaultApi.UpdateLiveActivity`: %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 | The OneSignal App ID for your app. Available in Keys & IDs.
activity_id = '12345' # String | Live Activity record ID
update_live_activity_request = OneSignal::UpdateLiveActivityRequest.new({name: 'name_example', event: 'update', event_updates: 3.56}) # UpdateLiveActivityRequest |
begin
# Update a Live Activity via Push
result = api_instance.update_live_activity(app_id, activity_id, update_live_activity_request)
p result
rescue OneSignal::ApiError => e
puts "Error when calling DefaultApi->update_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 | The OneSignal App ID for your app. Available in Keys & IDs.
String activityId = "12345"; // String | Live Activity record ID
UpdateLiveActivityRequest updateLiveActivityRequest = new UpdateLiveActivityRequest(); // UpdateLiveActivityRequest |
try {
UpdateLiveActivitySuccessResponse result = apiInstance.updateLiveActivity(appId, activityId, updateLiveActivityRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#updateLiveActivity");
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 UpdateLiveActivityExample
{
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 | The OneSignal App ID for your app. Available in Keys & IDs.
var activityId = "12345"; // string | Live Activity record ID
var updateLiveActivityRequest = new UpdateLiveActivityRequest(); // UpdateLiveActivityRequest |
try
{
// Update a Live Activity via Push
UpdateLiveActivitySuccessResponse result = apiInstance.UpdateLiveActivity(appId, activityId, updateLiveActivityRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.UpdateLiveActivity: " + 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_id: &str = "12345";
let update_live_activity_request: models::UpdateLiveActivityRequest = todo!();
match default_api::update_live_activity(&configuration, app_id, activity_id, update_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!("update_live_activity failed: {:?}", e.error_messages());
}
Err(e) => eprintln!("update_live_activity failed: {:?}", e),
}
}{
"id": "<string>"
}{
"errors": [
"Reason for the message not being started. Usually due to the activity type not being found in the app."
]
}{
"errors": [
"activity_id not found in this app"
]
}{
"errors": [
"API rate limit exceeded"
]
}{
"errors": [
"Service temporarily unavailable"
]
}Update Live Activity
Update the content of a running iOS Live Activity or end it with the OneSignal REST API. Covers required body fields, update priority, and dismissal timing.
curl --request POST \
--url https://api.onesignal.com/apps/{app_id}/live_activities/{activity_id}/notifications \
--header 'Authorization: <authorization>' \
--header 'Content-Type: <content-type>' \
--data '
{
"event_updates": {},
"name": "<string>",
"stale_date": 123,
"dismissal_date": 123,
"ios_sound": "<string>",
"ios_relevance_score": 123
}
'import Onesignal from '@onesignal/node-onesignal';
const configuration = Onesignal.createConfiguration({
restApiKey: 'YOUR_REST_API_KEY',
});
const apiInstance = new Onesignal.DefaultApi(configuration);
// string | The OneSignal App ID for your app. Available in Keys & IDs.
const appId: string = "YOUR_APP_ID";
// string | Live Activity record ID
const activityId: string = "12345";
// UpdateLiveActivityRequest
const updateLiveActivityRequest: Onesignal.UpdateLiveActivityRequest = {
name: "name_example",
event: "update",
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",
},
sound: "sound_example",
ios_sound: "ios_sound_example",
stale_date: 1,
dismissal_date: 1,
priority: 1,
ios_relevance_score: 3.14,
};
try {
const response = await apiInstance.updateLiveActivity(appId, activityId, updateLiveActivityRequest);
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("updateLiveActivity 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" # The OneSignal App ID for your app. Available in Keys & IDs.
activity_id = "12345" # Live Activity record ID
update_live_activity_request = UpdateLiveActivityRequest(
name="name_example",
event="update",
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",
),
sound="sound_example",
ios_sound="ios_sound_example",
stale_date=1,
dismissal_date=1,
priority=1,
ios_relevance_score=3.14,
)
try:
# Update a Live Activity via Push
api_response = api_instance.update_live_activity(app_id, activity_id, update_live_activity_request)
pprint(api_response)
except onesignal.ApiException as e:
print("Exception when calling DefaultApi->update_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 | The OneSignal App ID for your app. Available in Keys & IDs.
$activity_id = '12345'; // string | Live Activity record ID
$update_live_activity_request = new \onesignal\client\model\UpdateLiveActivityRequest(); // \onesignal\client\model\UpdateLiveActivityRequest
try {
$result = $apiInstance->updateLiveActivity($app_id, $activity_id, $update_live_activity_request);
print_r($result);
} catch (\onesignal\client\ApiException $e) {
echo 'Exception when calling DefaultApi->updateLiveActivity: ', $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->updateLiveActivity: ', $e->getMessage(), PHP_EOL;
}package main
import (
"context"
"fmt"
"os"
"github.com/OneSignal/onesignal-go-api/v5"
)
func main() {
appId := "YOUR_APP_ID" // string | The OneSignal App ID for your app. Available in Keys & IDs.
activityId := "12345" // string | Live Activity record ID
updateLiveActivityRequest := *onesignal.NewUpdateLiveActivityRequest("Name_example", "Event_example", map[string]interface{}{"key": "value"}) // UpdateLiveActivityRequest |
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.UpdateLiveActivity(restAuth, appId, activityId).UpdateLiveActivityRequest(updateLiveActivityRequest).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DefaultApi.UpdateLiveActivity``: %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 `UpdateLiveActivity`: UpdateLiveActivitySuccessResponse
fmt.Fprintf(os.Stdout, "Response from `DefaultApi.UpdateLiveActivity`: %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 | The OneSignal App ID for your app. Available in Keys & IDs.
activity_id = '12345' # String | Live Activity record ID
update_live_activity_request = OneSignal::UpdateLiveActivityRequest.new({name: 'name_example', event: 'update', event_updates: 3.56}) # UpdateLiveActivityRequest |
begin
# Update a Live Activity via Push
result = api_instance.update_live_activity(app_id, activity_id, update_live_activity_request)
p result
rescue OneSignal::ApiError => e
puts "Error when calling DefaultApi->update_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 | The OneSignal App ID for your app. Available in Keys & IDs.
String activityId = "12345"; // String | Live Activity record ID
UpdateLiveActivityRequest updateLiveActivityRequest = new UpdateLiveActivityRequest(); // UpdateLiveActivityRequest |
try {
UpdateLiveActivitySuccessResponse result = apiInstance.updateLiveActivity(appId, activityId, updateLiveActivityRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DefaultApi#updateLiveActivity");
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 UpdateLiveActivityExample
{
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 | The OneSignal App ID for your app. Available in Keys & IDs.
var activityId = "12345"; // string | Live Activity record ID
var updateLiveActivityRequest = new UpdateLiveActivityRequest(); // UpdateLiveActivityRequest |
try
{
// Update a Live Activity via Push
UpdateLiveActivitySuccessResponse result = apiInstance.UpdateLiveActivity(appId, activityId, updateLiveActivityRequest);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling DefaultApi.UpdateLiveActivity: " + 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_id: &str = "12345";
let update_live_activity_request: models::UpdateLiveActivityRequest = todo!();
match default_api::update_live_activity(&configuration, app_id, activity_id, update_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!("update_live_activity failed: {:?}", e.error_messages());
}
Err(e) => eprintln!("update_live_activity failed: {:?}", e),
}
}{
"id": "<string>"
}{
"errors": [
"Reason for the message not being started. Usually due to the activity type not being found in the app."
]
}{
"errors": [
"activity_id not found in this app"
]
}{
"errors": [
"API rate limit exceeded"
]
}{
"errors": [
"Service temporarily unavailable"
]
}Overview
Update or terminate running iOS Live Activities using our REST API. This endpoint enables real-time content updates and activity termination, ensuring dynamic, context-aware user experiences. Before using this API, ensure your app is properly configured by following the Live Activities developer setup.How to use this API
Select the Live Activity
activity_id of the Live Activity you want to update in the URL. The activity_id is a topic key: this request fans out to every device registered under it, whether that is one user tracking their delivery or every user following the same live game. See Choose an activity ID.Devices register under an activity_id when you:- Start the activity with the Start Live Activity API
- Start the activity in-app while following the Live Activities developer setup
- Call the
LiveActivities.enterSDK method
Set the required body fields
event, event_updates, and name. Requests missing any of them return a 400 error.Choose whether to update or end the activity
event to update to change the content of a running Live Activity, or to end to terminate it. See Update a running Live Activity and End a Live Activity below.Update a running Live Activity
Setevent to update and set event_updates to a JSON object that matches the structure of the ActivityAttributes.ContentState struct defined in your Live Activity widget extension. Missing or mismatched fields can prevent the Live Activity from updating. Set name to an internal label for the message, up to 128 characters. Recipients never see the name.
Set priority to control urgency. 10 delivers immediately and counts against the budget Apple imposes per device for high-priority updates. 5 delivers opportunistically and does not count against the budget, so there is no limit on how many you send. When you omit priority, OneSignal sends 10 and spends budget, which is the most common reason apps hit throttling. Try 5 first and reserve 10 for updates that need the user’s immediate attention. See Update frequency and throttling.
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": "update",
"event_updates": {
"quarter": 4,
"homeScore": 92,
"awayScore": 88,
"inTimeout": true
},
"contents": {
"en": "Home 92, Away 88"
},
"name": "Score update"
}
End a Live Activity
Setevent to end to terminate the Live Activity. Include event_updates and name in this request as well, since both remain required.
- If you omit
dismissal_date, iOS keeps the Live Activity visible for up to 4 hours after the end event, then removes it. - Include a
dismissal_dateif you want the Live Activity dismissed in less than 4 hours. - Set
dismissal_dateto a Unix timestamp in the past to dismiss the Live Activity immediately. The user must have allowed the Live Activity for it to be removed programmatically.
activity_id again. Later requests to the same activity_id, including changes to dismissal_date or event, do not take effect.{
"event": "end",
"event_updates": {
"quarter": 4,
"homeScore": 98,
"awayScore": 95,
"inTimeout": false
},
"contents": {
"en": "Final: Home 98, Away 95"
},
"name": "Game over",
"dismissal_date": 1663177260
}
FAQ
Why isn’t my Live Activity dismissing immediately?
Confirm thatdismissal_date is a Unix timestamp in seconds that is already in the past, such as 1663177260. If the timestamp is correct, the user may not have allowed the Live Activity, which iOS requires before an activity can be removed programmatically. A third possibility is that an earlier request already ended this activity_id, in which case the new request has no effect.
Does one request update every device?
Yes. Every device registered under thatactivity_id receives the update, so you do not target individual subscriptions when updating. That is why the activity_id should identify a topic, such as game-1234 for content everyone sees or order-98765 for content specific to one user. See Choose an activity ID.
Why did my request return a 400 error?
The most common cause is a missing required field.event, event_updates, and name are all required on every request, including requests that end the Live Activity.Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
The topic key of the Live Activity to update, set when the activity started. This request fans out to every device registered under this value. See Choose an activity ID.
Body
The action to perform on the Live Activity. update updates the content of an existing Live Activity without ending it. end ends the Live Activity and removes it from the user's view. See Apple's developer docs on Starting and updating Live Activities.
update, end 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
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.
A Unix timestamp (in seconds) indicating when the Live Activity should be removed from the user's device. Use with the end event. If not set, the Live Activity is dismissed automatically after 4 hours. To dismiss immediately, the user must have already allowed the Live Activity, then set a timestamp in the past (for example 1663177260). Alternatively, provide a date within a four-hour window to dismiss before the default 4-hour period. See Apple's documentation for more.
Set the urgency of this update. 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.
Response
201
The ID of the Live Activity update request.
Was this page helpful?