Use the ably push batch-publish command to publish push notifications to multiple recipients in a batch.
Synopsis
ably push batch-publish [payload] [options]Arguments
payload
A JSON array of push notification payloads. This can be provided as an inline JSON string, a file path (for example ./notifications.json or @notifications.json), or - to read from stdin.
Each item must have either a recipient or channels key. Items with channels are routed via channel-based push. Channel items may include an optional message field with realtime message data (plain text or JSON object) to publish alongside the push notification. In a JSON object, the recognized message fields name, data, and extras are mapped directly; any other fields are merged into data.
Options
--force | -f
Skip confirmation when publishing to channels. Required when using --json. The default is false.
--json
Output results as compact JSON. Mutually exclusive with --pretty-json.
--pretty-json
Output results in formatted JSON. Mutually exclusive with --json.
--verbose | -v
Enable verbose logging. Can be combined with --json or --pretty-json.
Examples
Publish to multiple recipients with an inline JSON payload:
ably push batch-publish '[{"recipient":{"deviceId":"device1"},"payload":{"notification":{"title":"Hello"}}},{"recipient":{"clientId":"user1"},"payload":{"notification":{"title":"Hi"}}}]'Publish from a file:
ably push batch-publish @notifications.jsonSee notification file example below.
Publish from stdin:
cat notifications.json | ably push batch-publish -Publish to a specific client:
ably push batch-publish '[{"recipient":{"clientId":"user-456"},"payload":{"notification":{"title":"Hello","body":"World"}}}]'Publish a data-only notification to a device:
ably push batch-publish '[{"recipient":{"deviceId":"device-123"},"payload":{"data":{"orderId":"123","action":"update"}}}]'Publish to a channel with a message string and a force option:
ably push batch-publish '[{"channels":["my-channel"],"payload":{"notification":{"title":"Hello","body":"World"}},"message":"Hello from push"}]' --forcePublish to multiple channels with a message JSON object:
ably push batch-publish '[{"channels":["channel-1","channel-2"],"payload":{"notification":{"title":"Alert","body":"Message"}},"message":{"name":"alert","data":"New alert"}}]' --forcePublish to device and channel recipients in one batch:
ably push batch-publish '[{"recipient":{"deviceId":"device-123"},"payload":{"notification":{"title":"Hello","body":"World"}}},{"channels":["my-channel"],"payload":{"notification":{"title":"Hello","body":"World"}},"message":{"name":"greeting","data":"Hello from push"}}]' --forcePublish from a file and output in JSON format:
ably push batch-publish ./notifications.json --json --forceNotifications.json file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[
{
"recipient": {"deviceId": "device-123"},
"payload": {
"notification": {"title": "Hello", "body": "World"}
}
},
{
"channels": ["my-channel"],
"payload": {
"notification": {"title": "Hello", "body": "World"}
},
"message": {"name": "greeting", "data": "Hello from push"}
}
]See also
- Push — Explore all
ably pushcommands. - CLI reference — Full list of available commands.