Skip to content

Commit dfa8e13

Browse files
owenpearsonGregHolmes
authored andcommitted
add batch push publish docs
1 parent de7a126 commit dfa8e13

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

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

+50
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,55 @@ 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 a push notification payload to multiple devices or browsers in a single request by specifying a list of recipients and corresponding payloads.
1159+
1160+
h6. POST rest.ably.io/push/admin/batch/publish
1161+
1162+
The request body is an array of objects of the form:
1163+
1164+
bc[json]. {
1165+
recipient: <object>
1166+
payload: <object>
1167+
}
1168+
1169+
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.
1170+
1171+
Example request:
1172+
1173+
bc[sh]. curl -X POST https://rest.ably.io/push/admin/batch/publish \
1174+
-u "{{API_KEY}}" \
1175+
-H "Content-Type: application/json" \
1176+
--data \
1177+
'
1178+
[
1179+
{
1180+
"recipient": {
1181+
"deviceId": "01ARZ3NDEKTSV4RRFFQ69G5FAV"
1182+
},
1183+
"payload": {
1184+
"notification": {
1185+
"title": "Message 1",
1186+
"body": "Example push notification from Ably."
1187+
}
1188+
}
1189+
},
1190+
{
1191+
"recipient": {
1192+
"clientId": "myClientId"
1193+
},
1194+
"payload": {
1195+
"notification": {
1196+
"title": "Message 2",
1197+
"body": "Example push notification from Ably."
1198+
}
1199+
}
1200+
}
1201+
]
1202+
'
1203+
1204+
11551205
h2(#authentication). Authentication
11561206

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

Diff for: content/push/publish.textile

+51
Original file line numberDiff line numberDiff line change
@@ -1226,3 +1226,54 @@ final message = Message(name: 'name', data: 'data', extras: extras);
12261226
channel = rest.channels.get('pushenabled:foo');
12271227
channel.publish(message);
12281228
```
1229+
1230+
1231+
h2(#via-batch-push-api). Publish via batch push API
1232+
1233+
The batch push API allows you to publish push notifications to multiple devices or browsers in a single request. This is useful for when you need to send a large number of push notifications on an ad-hoc basis (ie when using push channel subscriptions is not practical).
1234+
1235+
The batch push endpoint accepts a JSON array of @PushPublishSpec@ objects, each of which contains a @recipient@ and a @payload@, where @payload@ is the same as the payload you would use in a normal direct publish request.
1236+
1237+
The following example shows how to publish multiple push notifications in one request using the batch API with the generic REST SDK @request@ method:
1238+
1239+
```[rest_javascript]
1240+
await rest.request('POST', '/push/admin/batch/publish', null, [
1241+
{
1242+
recipient: {
1243+
deviceId: 'xxxxxxxxxxx'
1244+
},
1245+
payload: {
1246+
notification: { title: 'Message 1', body: 'Example push notification from Ably.' }
1247+
}
1248+
},
1249+
{
1250+
recipient: {
1251+
deviceId: 'xxxxxxxxxxx'
1252+
},
1253+
payload: {
1254+
notification: { title: 'Message 2', body: 'Example push notification from Ably.' }
1255+
}
1256+
}
1257+
])
1258+
```
1259+
1260+
```[rest_nodejs]
1261+
await rest.request('POST', '/push/admin/batch/publish', null, [
1262+
{
1263+
recipient: {
1264+
deviceId: 'xxxxxxxxxxx'
1265+
},
1266+
payload: {
1267+
notification: { title: 'Message 1', body: 'Example push notification from Ably.' }
1268+
}
1269+
},
1270+
{
1271+
recipient: {
1272+
deviceId: 'xxxxxxxxxxx'
1273+
},
1274+
payload: {
1275+
notification: { title: 'Message 2', body: 'Example push notification from Ably.' }
1276+
}
1277+
}
1278+
])
1279+
```

0 commit comments

Comments
 (0)