Subscribe from the CLI
You can subscribe to topics and receive messages directly in your terminal using the ntfy CLI or standard command-line tools.
Using curl
The simplest way to subscribe is using curl with server-sent events:
curl -s https://app.notifyhero.com/mytopic/sse
This will print messages as they arrive in real-time.
JSON format
For easier parsing in scripts:
curl -s https://app.notifyhero.com/mytopic/json
Each message appears as a JSON object on a single line:
{"id":"abc123","time":1234567890,"event":"message","topic":"mytopic","message":"Hello!"}
Raw format
For simple text output:
curl -s https://app.notifyhero.com/mytopic/raw
This outputs just the message body, one per line.
Using the ntfy CLI
If you prefer a dedicated CLI tool:
Install
# macOS
brew install ntfy
# Debian/Ubuntu
sudo apt install ntfy
# From source
go install heckel.io/ntfy/v2@latest
Subscribe
ntfy subscribe mytopic
Or with a different server:
ntfy subscribe --server https://app.notifyhero.com mytopic
Publish
ntfy publish mytopic "Hello from CLI!"
Scripting Examples
Watch for messages
#!/bin/bash
curl -s https://app.notifyhero.com/mytopic/json | while read -r line; do
message=$(echo "$line" | jq -r '.message')
echo "Received: $message"
done
Trigger on message
#!/bin/bash
curl -s https://app.notifyhero.com/deploy/json | while read -r line; do
event=$(echo "$line" | jq -r '.event')
if [ "$event" = "message" ]; then
message=$(echo "$line" | jq -r '.message')
echo "Deploying: $message"
./deploy.sh
fi
done
Poll for messages
If you don't want a persistent connection:
# Get messages from last hour
curl -s "https://app.notifyhero.com/mytopic/json?since=1h"
# Get all cached messages
curl -s "https://app.notifyhero.com/mytopic/json?poll=1"
Response Format
SSE (Server-Sent Events)
event: message
data: {"id":"abc","message":"Hello"}
event: message
data: {"id":"def","message":"World"}
JSON (newline-delimited)
{"id":"abc","event":"message","message":"Hello"}
{"id":"def","event":"message","message":"World"}
Event Types
| Event | Description |
|-------|-------------|
| open | Connection opened |
| message | New message received |
| keepalive | Connection keepalive (every 30s) |
Query Parameters
| Parameter | Description | Example |
|-----------|-------------|---------|
| since | Return messages since time | since=1h, since=1234567890 |
| poll | Return cached messages and close | poll=1 |
| scheduled | Include scheduled messages | scheduled=1 |
| auth | Authentication token | auth=tk_xxx |
Authentication
If the topic requires authentication:
# Basic auth
curl -u user:password https://app.notifyhero.com/mytopic/json
# Bearer token
curl -H "Authorization: Bearer tk_xxx" https://app.notifyhero.com/mytopic/json
Multiple Topics
Subscribe to multiple topics at once:
curl -s "https://app.notifyhero.com/topic1,topic2,topic3/json"
Tips
- Use
jqfor parsing JSON output - Use
--retrywith curl for automatic reconnection - Pipe to
teeto log messages while processing - Use
nohuporscreenfor persistent subscriptions