Sending a notification to all devices subscribed to a topic
Request
To send a notification to all the registered devices that are subscribed to a particular topic, send a POST request to:
http://<host>:<port>/messaging/v1/topics/{topic_name}/inbox
Headers
Content-Type: application/json
Mandatory fields
topic_name(in URL) – the name of the topicenvelopeobject containing at least:from– who the notification is from
message– the message – a string or JSON converted to a string (that is, with line breaks removed and special characters escaped).
See Message format – general notifications for a detailed explanation of the expected message format.
Withinmessage:Include a
notificationblock if the notification is meant to be presented immediately to the user.Omit the
notificationblock if the client should store the notification so that the user can view it when they choose to (for example, in an inbox).
Example
A request with this payload sends a message to all the devices that are subscribed to the topic specified in the URL:
{
"envelope": {
"from": "Operator"
},
"message":"{
"notification": {
"body": "20% off all TVOD until Sunday",
"title": "Discount Movies"
},
"data": {
"body": "20% off all TVOD until Sunday",
"title": "Discount Movies",
"referenceType": "NOTIFICATION_UPDATE"
}
}"
}
Note that "message" in the JSON above is shown with line breaks and is unescaped for clarity. In reality, you must remove all line breaks and escape all relevant characters within "message".nt characters within "message".
The JSON that you would actually use as the body of the request is:
{
"envelope": {
"from": "Operator"
},
"message":"{\"notification\":{\"body\":\"20% off all TVOD until Sunday\",\"title\":\"Discount Movies\"},\"data\":{\"body\":\"20% off all TVOD until Sunday\",\"title\":\"Discount Movies\",\"referenceType\":\"NOTIFICATION_UPDATE\"}}"
}
Response
The request returns an HTTP 200 status if the message was sent successfully.
An unsuccessful request returns an HTTP 404 status if the topic is not recognised.
See also
For full details of this API, see the Device Messaging Manager (DMM) API documentation v1.