Skip to content

Commit 99e185a

Browse files
committed
add batch push publish docs
1 parent 3470bcc commit 99e185a

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

Diff for: content/api/rest-api.textile

+51
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jump_to:
2929
- list channel subscriptions#list-channel-subscriptions
3030
- list channels#list-channels
3131
- publish directly to device#push-publish
32+
- publish via batch push API#push-publish-batch
3233
Authentication API:
3334
- requestToken#request-token
3435
- revokeTokens#revoke-tokens
@@ -1152,6 +1153,56 @@ A successful request returns an empty response.
11521153

11531154
An unsuccessful request returns an error.
11541155

1156+
h3(#push-publish-batch). Publish via batch push API
1157+
1158+
Convenience endpoint to deliver multiple push notification payloads to multiple devices or browsers in a single request by specifying a list of recipients and corresponding payloads.
1159+
Currently the batch push endpoint allows a maximum of 10,000 recipients per request (recipients are counted per payload, so publishing two payloads to the same recipient counts as two recipients).
1160+
1161+
h6. POST rest.ably.io/push/batch/publish
1162+
1163+
The request body is an array of objects of the form:
1164+
1165+
bc[json]. {
1166+
recipient: <recipient object or array of recipient objects>
1167+
payload: <object>
1168+
}
1169+
1170+
Where the recipient and payload fields are the same as those used in the "Publish a push notification to a single device":#push-publish endpoint.
1171+
1172+
Example request:
1173+
1174+
bc[sh]. curl -X POST https://rest.ably.io/push/admin/batch/publish \
1175+
-u "{{API_KEY}}" \
1176+
-H "Content-Type: application/json" \
1177+
--data \
1178+
'
1179+
[
1180+
{
1181+
"recipient": {
1182+
"deviceId": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
1183+
},
1184+
"payload": {
1185+
"notification": {
1186+
"title": "Message 1",
1187+
"body": "Example push notification from Ably."
1188+
}
1189+
}
1190+
},
1191+
{
1192+
"recipient": {
1193+
"clientId": "myClientId"
1194+
},
1195+
"payload": {
1196+
"notification": {
1197+
"title": "Message 2",
1198+
"body": "Example push notification from Ably."
1199+
}
1200+
}
1201+
}
1202+
]
1203+
'
1204+
1205+
11551206
h2(#authentication). Authentication
11561207

11571208
h3(#request-token). Request an access token

Diff for: content/push/publish.textile

+60
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,66 @@ var notification = new
778778
rest.Push.Admin.Publish(recipient, notification);
779779
```
780780

781+
h3(#via-batch-push-api). Publish via batch push API
782+
783+
The batch push API allows you to publish push notifications to multiple devices or browsers in a single request. This is useful when you need to send a large number of distinct push notifications to multiple recipients. If you are publishing the same notification to multiple recipients, prefer publishing "via channels":#via-channels.
784+
The batch push endpoint accepts a JSON array of @PushPublishSpec@ objects, each of which contains a @recipient@ or array of recipients, and a @payload@, where @payload@ is the same as the payload you would use in a normal direct publish request.
785+
Currently the batch push endpoint allows a maximum of 10,000 recipients per request (recipients are counted per payload, so publishing two payloads to the same recipient counts as two recipients).
786+
787+
The following example shows how to publish multiple push notifications in one request using the batch API with the generic REST SDK @request@ method:
788+
789+
```[rest_javascript]
790+
await rest.request('POST', '/push/batch/publish', null, [
791+
{
792+
recipient: {
793+
deviceId: 'xxxxxxxxxxx'
794+
},
795+
payload: {
796+
notification: { title: 'Message 1', body: 'Example push notification from Ably.' }
797+
}
798+
},
799+
{
800+
recipient: [
801+
{
802+
deviceId: 'xxxxxxxxxxx'
803+
},
804+
{
805+
deviceId: 'xxxxxxxxxxx',
806+
}
807+
],
808+
payload: {
809+
notification: { title: 'Message 2', body: 'Example push notification from Ably.' }
810+
}
811+
}
812+
])
813+
```
814+
815+
```[rest_nodejs]
816+
await rest.request('POST', '/push/batch/publish', null, [
817+
{
818+
recipient: {
819+
deviceId: 'xxxxxxxxxxx'
820+
},
821+
payload: {
822+
notification: { title: 'Message 1', body: 'Example push notification from Ably.' }
823+
}
824+
},
825+
{
826+
recipient: [
827+
{
828+
deviceId: 'xxxxxxxxxxx'
829+
},
830+
{
831+
deviceId: 'xxxxxxxxxxx',
832+
}
833+
],
834+
payload: {
835+
notification: { title: 'Message 2', body: 'Example push notification from Ably.' }
836+
}
837+
}
838+
])
839+
```
840+
781841
h2(#via-channels). Publish via channels
782842

783843
Publishing via channels is modeled on Ably's "channel":#channels infrastructure, facilitating the delivery of push notifications across a network of subscribed devices or browsers. This process publishes messages through predefined channels, which devices or browsers must "subscribe":#sub-channels to in order to receive updates. This process ensures registered devices or browsers in the specified channels receive the correct push notifications. Publishing via channels is particularly useful for publishing notifications to multiple groups with varying privileges.

0 commit comments

Comments
 (0)