Spaces:
Paused
Title: Sending messages - ntfy
URL Source: https://docs.ntfy.sh/publish
Markdown Content: Skip to content If you like ntfy, please consider sponsoring me via GitHub Sponsors or Liberapay , or subscribing to ntfy Pro. ntfy Sending messages
Initializing search binwiederhier/ntfy ntfy Getting started Publishing Publishing Sending messages Table of contents Message title Message priority Tags & emojis 🥳 🎉 Markdown formatting Scheduled delivery Webhooks (publish via GET) Message templating Pre-defined templates Custom templates Inline templating Template syntax Template functions Publish as JSON Action buttons Defining actions Using a header Using a JSON array Open website/app Send Android broadcast Send HTTP request Click action Attachments Attach local file Attach file from a URL Icons E-mail notifications E-mail publishing Phone calls Authentication Username + password Access tokens Query param Advanced features Message caching Disable Firebase UnifiedPush Matrix Gateway Public topics Limitations List of all parameters Subscribing Subscribing From your phone From the Web app From the Desktop From the CLI Using the API Self-hosting Self-hosting Installation Configuration Other things Other things FAQs Examples Integrations + projects Release notes Emojis 🥳 🎉 Template functions Troubleshooting Known issues Deprecation notices Development Privacy policy Publishing¶
Publishing messages can be done via HTTP PUT/POST or via the ntfy CLI. Topics are created on the fly by subscribing or publishing to them. Because there is no sign-up, the topic is essentially a password, so pick something that's not easily guessable.
Here's an example showing how to publish a simple message using a POST request:
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -d "Backup successful 😀" ntfy.sh/mytopic
If you have the Android app installed on your phone, this will create a notification that looks like this:
Android notification
There are more features related to publishing messages: You can set a notification priority, a title, and tag messages 🥳 🎉. Here's an example that uses some of them at together:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-H "Title: Unauthorized access detected"
-H "Priority: urgent"
-H "Tags: warning,skull"
-d "Remote access to phils-laptop detected. Act right away."
ntfy.sh/phil_alerts
Urgent notification with tags and title
You can also do multi-line messages. Here's an example using a click action, an action button, an external image attachment and email publishing:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-H "Click: https://home.nest.com/"
-H "Attach: https://nest.com/view/yAxkasd.jpg"
-H "Actions: http, Open door, https://api.nest.com/open/yAxkasd, clear=true"
-H "Email: [email protected]"
-d "There's someone at the door. 🐶
Please check if it's a good boy or a hooman.
Doggies have been known to ring the doorbell."
ntfy.sh/mydoorbell
Notification using a click action, a user action, with an external image attachment and forwarded via email Message title¶
Supported on:
The notification title is typically set to the topic short URL (e.g. ntfy.sh/mytopic). To override the title, you can set the X-Title header (or any of its aliases: Title, ti, or t).
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "X-Title: Dogs are better than cats" -d "Oh my ..." ntfy.sh/controversial curl -H "Title: Dogs are better than cats" -d "Oh my ..." ntfy.sh/controversial curl -H "t: Dogs are better than cats" -d "Oh my ..." ntfy.sh/controversial
Detail view of notification with title
Info
ntfy supports UTF-8 in HTTP headers, but not every library or programming language does. If non-ASCII characters are causing issues for you in the title (i.e. you're seeing ? symbols), you may also encode any header (including the title) as RFC 2047, e.g. =?UTF-8?B?8J+HqfCfh6o=?= (base64), or =?UTF-8?Q?=C3=84pfel?= (quoted-printable).
Message priority¶
Supported on:
All messages have a priority, which defines how urgently your phone notifies you. On Android, you can set custom notification sounds and vibration patterns on your phone to map to these priorities (see Android config).
The following priorities exist:
Priority Icon ID Name Description Max priority 5 max/urgent Really long vibration bursts, default notification sound with a pop-over notification. High priority 4 high Long vibration burst, default notification sound with a pop-over notification. Default priority (none) 3 default Short default vibration and sound. Default notification behavior. Low priority 2 low No vibration or sound. Notification will not visibly show up until notification drawer is pulled down. Min priority 1 min No vibration or sound. The notification will be under the fold in "Other notifications".
You can set the priority with the header X-Priority (or any of its aliases: Priority, prio, or p).
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "X-Priority: 5" -d "An urgent message" ntfy.sh/phil_alerts curl -H "Priority: low" -d "Low priority message" ntfy.sh/phil_alerts curl -H p:4 -d "A high priority message" ntfy.sh/phil_alerts
Detail view of priority notifications Tags & emojis 🥳 🎉¶
Supported on:
You can tag messages with emojis and other relevant strings:
Emojis: If a tag matches an emoji short code, it'll be converted to an emoji and prepended to title or message. Other tags: If a tag doesn't match, it will be listed below the notification.
This feature is useful for things like warnings (⚠️, ️🚨, or 🚩), but also to simply tag messages otherwise (e.g. script names, hostnames, etc.). Use the emoji short code list to figure out what tags can be converted to emojis. Here's an excerpt of emojis I've found very useful in alert messages:
Tag Emoji +1 👍 partying_face 🥳 tada 🎉 heavy_check_mark ✔️ loudspeaker 📢 ... ... Tag Emoji -1 👎️ warning ⚠️ rotating_light ️🚨 triangular_flag_on_post 🚩 skull 💀 ... ... Tag Emoji facepalm 🤦 no_entry ⛔ no_entry_sign 🚫 cd 💿 computer 💻 ... ...
You can set tags with the X-Tags header (or any of its aliases: Tags, tag, or ta). Specify multiple tags by separating them with a comma, e.g. tag1,tag2,tag3.
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "X-Tags: warning,mailsrv13,daily-backup" -d "Backup of mailsrv13 failed" ntfy.sh/backups curl -H "Tags: horse,unicorn" -d "Unicorns are just horses with unique horns" ntfy.sh/backups curl -H ta:dog -d "Dogs are awesome" ntfy.sh/backups
Detail view of notifications with tags
Info
ntfy supports UTF-8 in HTTP headers, but not every library or programming language does. If non-ASCII characters are causing issues for you in the title (i.e. you're seeing ? symbols), you may also encode the tags header or individual tags as RFC 2047, e.g. tag1,=?UTF-8?B?8J+HqfCfh6o=?= (base64), or =?UTF-8?Q?=C3=84pfel?=,tag2 (quoted-printable).
Markdown formatting¶
Supported on:
You can format messages using Markdown 🤩. That means you can use bold text, italicized text, links, images, and more. Supported Markdown features (web app only for now):
Emphasis such as bold (bold), italics (italics)
Links (some tool)
Images (
)
Code blocks (code blocks) and inline code (inline code)
Headings (# headings, ## headings, etc.)
Lists (- lists, 1. lists, etc.)
Blockquotes (> blockquotes)
Horizontal rules (---)
By default, messages sent to ntfy are rendered as plain text. To enable Markdown, set the X-Markdown header (or any of its aliases: Markdown, or md) to true (or 1 or yes), or set the Content-Type header to text/markdown. As of today, Markdown is only supported in the web app. Here's an example of how to enable Markdown formatting:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "Look ma, bold text, italics, ..."
-H "Markdown: yes"
ntfy.sh/mytopic
Here's what that looks like in the web app:
Markdown formatting in the web app Scheduled delivery¶
Supported on:
You can delay the delivery of messages and let ntfy send them at a later date. This can be used to send yourself reminders or even to execute commands at a later date (if your subscriber acts on messages).
Usage is pretty straight forward. You can set the delivery time using the X-Delay header (or any of its aliases: Delay, X-At, At, X-In or In), either by specifying a Unix timestamp (e.g. 1639194738), a duration (e.g. 30m, 3h, 2 days), or a natural language time string (e.g. 10am, 8:30pm, tomorrow, 3pm, Tuesday, 7am, and more).
As of today, the minimum delay you can set is 10 seconds and the maximum delay is 3 days. This can be configured with the message-delay-limit option).
For the purposes of message caching, scheduled messages are kept in the cache until 12 hours after they were delivered (or whatever the server-side cache duration is set to). For instance, if a message is scheduled to be delivered in 3 days, it'll remain in the cache for 3 days and 12 hours. Also note that naturally, turning off server-side caching is not possible in combination with this feature.
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "At: tomorrow, 10am" -d "Good morning" ntfy.sh/hello curl -H "In: 30min" -d "It's 30 minutes later now" ntfy.sh/reminder curl -H "Delay: 1639194738" -d "Unix timestamps are awesome" ntfy.sh/itsaunixsystem
Here are a few examples (assuming today's date is 12/10/2021, 9am, Eastern Time Zone):
Delay/At/In header Message will be delivered at Explanation 30m 12/10/2021, 9:30am 30 minutes from now 2 hours 12/10/2021, 11:30am 2 hours from now 1 day 12/11/2021, 9am 24 hours from now 10am 12/10/2021, 10am Today at 10am (same day, because it's only 9am) 8am 12/11/2021, 8am Tomorrow at 8am (because it's 9am already) 1639152000 12/10/2021, 11am (EST) Today at 11am (EST) Webhooks (publish via GET)¶
Supported on:
In addition to using PUT/POST, you can also send to topics via simple HTTP GET requests. This makes it easy to use a ntfy topic as a webhook, or if your client has limited HTTP support.
To send messages via HTTP GET, simply call the /publish endpoint (or its aliases /send and /trigger). Without any arguments, this will send the message triggered to the topic. However, you can provide all arguments that are also supported as HTTP headers as URL-encoded arguments. Be sure to check the list of all supported parameters and headers for details.
For instance, assuming your topic is mywebhook, you can simply call /mywebhook/trigger to send a message (aka trigger the webhook):
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl ntfy.sh/mywebhook/trigger
To add a custom message, simply append the message= URL parameter. And of course you can set the message priority, the message title, and tags as well. For a full list of possible parameters, check the list of supported parameters and headers.
Here's an example with a custom message, tags and a priority:
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl "ntfy.sh/mywebhook/publish?message=Webhook+triggered&priority=high&tags=warning,skull"
Message templating¶
Supported on:
Templating lets you format a JSON message body into human-friendly message and title text using Go templates (see tutorials here, here, and here). This is specifically useful when combined with webhooks from services such as GitHub, Grafana, Alertmanager, or other services that emit JSON webhooks.
Instead of using a separate bridge program to parse the webhook body into the format ntfy expects, you can include a templated message and/or a templated title which will be populated based on the fields of the webhook body (so long as the webhook body is valid JSON).
You can enable templating by setting the X-Template header (or its aliases Template or tpl, or the query parameter ?template=...):
Pre-defined template files: Setting the X-Template header or query parameter to a pre-defined template name (one of github, grafana, or alertmanager, such as ?template=github) will use the built-in template with that name. See pre-defined templates for more details. Custom template files: Setting the X-Template header or query parameter to a custom template name (e.g. ?template=myapp) will use a custom template file from the template directory (defaults to /etc/ntfy/templates, can be overridden with template-dir). See custom templates for more details. Inline templating: Setting the X-Template header or query parameter to yes or 1 (e.g. ?template=yes) will enable inline templating, which means that the message and/or title will be parsed as a Go template. See inline templating for more details.
To learn the basics of Go's templating language, please see template syntax.
Pre-defined templates¶
When X-Template: (aliases: Template: , Tpl: ) or ?template= is set, ntfy will transform the message and/or title based on one of the built-in pre-defined templates.
The following pre-defined templates are available:
github: Formats a subset of GitHub webhook payloads (PRs, issues, new star, new watcher, new comment). See github.yml. grafana: Formats Grafana webhook payloads (firing/resolved alerts). See grafana.yml. alertmanager: Formats Alertmanager webhook payloads (firing/resolved alerts). See alertmanager.yml.
To override the pre-defined templates, you can place a file with the same name in the template directory (defaults to /etc/ntfy/templates, can be overridden with template-dir). See custom templates for more details.
Here's an example of how to use the pre-defined github template:
First, configure the webhook in GitHub to send a webhook to your ntfy topic, e.g. https://ntfy.sh/mytopic?template=github.
GitHub webhook configuration
After that, when GitHub publishes a JSON webhook to the topic, ntfy will transform it according to the template rules and you'll receive notifications in the ntfy app. Here's an example for when somebody stars your repository:
Receiving a webhook, formatted using the pre-defined "github" template Custom templates¶
To define your own custom templates, place a template file in the template directory (defaults to /etc/ntfy/templates, can be overridden with template-dir) and set the X-Template header or query parameter to the name of the template file (without the .yml extension).
For example, if you have a template file /etc/ntfy/templates/myapp.yml, you can set the header X-Template: myapp or the query parameter ?template=myapp to use it.
Template files must have the .yml (not: .yaml!) extension and must be formatted as YAML. They may contain title and message keys, which are interpreted as Go templates.
Here's an example custom template:
Custom template (/etc/ntfy/templates/myapp.yml) title: | {{- if eq .status "firing" }} {{- if gt .percent 90.0 }}🚨 Critical alert {{- else }}⚠️ Alert{{- end }} {{- else if eq .status "resolved" }} ✅ Alert resolved {{- end }} message: | Status: {{ .status }} Type: {{ .type | upper }} ({{ .percent }}%) Server: {{ .server }}
Once you have the template file in place, you can send the payload to your topic using the X-Template header or query parameter:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
echo '{"status":"firing","type":"cpu","server":"ntfy.sh","percent":99}' |
curl -sT- "https://ntfy.example.com/mytopic?template=myapp"
Which will result in a notification that looks like this:
JSON webhook, transformed using a custom template Inline templating¶
When X-Template: yes (aliases: Template: yes, Tpl: yes) or ?template=yes is set, you can use Go templates in the message and title fields of your webhook payload.
Inline templates are most useful for templated one-off messages, or if you do not control the ntfy server (e.g., if you're using ntfy.sh). Consider using pre-defined templates or custom templates instead, if you control the ntfy server, as templates are much easier to maintain.
Here's an example for a Grafana alert:
Grafana webhook, formatted using templates
This was sent using the following templates and payloads
Message template Title template Encoded webhook URL Grafana-sent payload {{range .alerts}} {{.annotations.summary}}
Values: {{range $k,$v := .values}} - {{$k}}={{$v}} {{end}} {{end}}
Here's an easier example with a shorter JSON payload:
Command line (curl) HTTP JavaScript Go PowerShell Python PHP
To use { and } in the URL without encoding, we need to turn off
curl's globbing using --globoff
curl
--globoff
-d '{"hostname": "phil-pc", "error": {"level": "severe", "desc": "Disk has run out of space"}}'
'ntfy.sh/mytopic?tpl=yes&t={{.hostname}}:+A+{{.error.level}}+error+has+occurred&m=Error+message:+{{.error.desc}}'
This example uses the message/m and title/t query parameters, but obviously this also works with the corresponding Message/Title headers. It will send a notification with a title phil-pc: A severe error has occurred and a message Error message: Disk has run out of space.
Template syntax¶
ntfy uses Go templates for its templates, which is arguably one of the most powerful, yet also one of the worst templating languages out there.
You can use the following features in your templates:
Variables, e.g. {{.alert.title}} or An error occurred: {{.error.desc}} Conditionals (if/else, e.g. {{if eq .action "opened"}}..{{else}}..{{end}}, see example) Loops (e.g. {{range .errors}}..{{end}}, see example)
A good way to experiment with Go templates is the Go Template Playground. It is highly recommended to test your templates there first (example for Grafana alert).
Template functions¶
ntfy supports a subset of the Sprig template functions (originally copied from Sprig, thank you to the Sprig developers 🙏). This is useful for advanced message templating and for transforming the data provided through the JSON payload.
Below are the functions that are available to use inside your message/title templates.
String Functions: trim, trunc, substr, plural, etc. String List Functions: splitList, sortAlpha, etc. Integer Math Functions: add, max, mul, etc. Integer List Functions: until, untilStep Float Math Functions: maxf, minf Date Functions: now, date, etc. Defaults Functions: default, empty, coalesce, fromJSON, toJSON, toPrettyJSON, toRawJSON, ternary Encoding Functions: b64enc, b64dec, etc. Lists and List Functions: list, first, uniq, etc. Dictionaries and Dict Functions: get, set, dict, hasKey, pluck, dig, etc. Type Conversion Functions: atoi, int64, toString, etc. Path and Filepath Functions: base, dir, ext, clean, isAbs, osBase, osDir, osExt, osClean, osIsAbs Flow Control Functions: fail Advanced Functions Reflection: typeOf, kindIs, typeIsLike, etc. Cryptographic and Security Functions: sha256sum, etc. URL: urlParse, urlJoin Publish as JSON¶
Supported on:
For some integrations with other tools (e.g. Jellyfin, overseerr), adding custom headers to HTTP requests may be tricky or impossible, so ntfy also allows publishing the entire message as JSON in the request body.
To publish as JSON, simple PUT/POST the JSON object directly to the ntfy root URL. The message format is described below the example.
Info
To publish as JSON, you must PUT/POST to the ntfy root URL, not to the topic URL. Be sure to check that you're POST-ing to https://ntfy.sh/ (correct), and not to https://ntfy.sh/mytopic (incorrect).
Here's an example using most supported parameters. Check the table below for a complete list. The topic parameter is the only required one:
Command line (curl)
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl ntfy.sh
-d '{
"topic": "mytopic",
"message": "Disk space is low at 5.1 GB",
"title": "Low disk space alert",
"tags": ["warning","cd"],
"priority": 4,
"attach": "https://filesrv.lan/space.jpg",
"filename": "diskspace.jpg",
"click": "https://homecamera.lan/xasds1h2xsSsa/",
"actions": [{ "action": "view", "label": "Admin panel", "url": "https://filesrv.lan/admin" }]
}'
The JSON message format closely mirrors the format of the message you can consume when you subscribe via the API (see JSON message format for details), but is not exactly identical. Here's an overview of all the supported fields:
Field Required Type Example Description topic ✔️ string topic1 Target topic name message - string Some message Message body; set to triggered if empty or not passed title - string Some title Message title tags - string array ["tag1","tag2"] List of tags that may or not map to emojis priority - int (one of: 1, 2, 3, 4, or 5) 4 Message priority with 1=min, 3=default and 5=max actions - JSON array (see action buttons) Custom user action buttons for notifications click - URL https://example.com Website opened when notification is clicked attach - URL https://example.com/file.jpg URL of an attachment, see attach via URL markdown - bool true Set to true if the message is Markdown-formatted icon - string https://example.com/icon.png URL to use as notification icon filename - string file.jpg File name of the attachment delay - string 30min, 9am Timestamp or duration for delayed delivery email - e-mail address [email protected] E-mail address for e-mail notifications call - phone number or 'yes' +1222334444 or yes Phone number to use for voice call Action buttons¶
Supported on:
You can add action buttons to notifications to allow yourself to react to a notification directly. This is incredibly useful and has countless applications.
You can control your home appliances (open/close garage door, change temperature on thermostat, ...), react to common monitoring alerts (clear logs when disk is full, ...), and many other things. The sky is the limit.
As of today, the following actions are supported:
view: Opens a website or app when the action button is tapped broadcast: Sends an Android broadcast intent when the action button is tapped (only supported on Android) http: Sends HTTP POST/GET/PUT request when the action button is tapped
Here's an example of what a notification with actions can look like:
Notification with two user actions Defining actions¶
You can define up to three user actions in your notifications, using either of the following methods:
In the X-Actions header, using a simple comma-separated format As a JSON array in the actions key, when publishing as JSON Using a header¶
To define actions using the X-Actions header (or any of its aliases: Actions, Action), use the following format:
Header format (long) Header format (short) action=, label=, paramN=... [; action=, label=, ...]
Multiple actions are separated by a semicolon (;), and key/value pairs are separated by commas (,). Values may be quoted with double quotes (") or single quotes (') if the value itself contains commas or semicolons.
The action= and label= prefix are optional in all actions, and the url= prefix is optional in the view and http action. The only limitation of this format is that depending on your language/library, UTF-8 characters may not work. If they don't, use the JSON array format instead.
As an example, here's how you can create the above notification using this format. Refer to the view action and http action section for details on the specific actions:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
body='{"temperature": 65}'
curl
-d "You left the house. Turn down the A/C?"
-H "Actions: view, Open portal, https://home.nest.com/, clear=true;
http, Turn down, https://api.nest.com/, body='$body'"
ntfy.sh/myhome
Info
ntfy supports UTF-8 in HTTP headers, but not every library or programming language does. If non-ASCII characters are causing issues for you in the title (i.e. you're seeing ? symbols), you may also encode any header (including actions) as RFC 2047, e.g. =?UTF-8?B?8J+HqfCfh6o=?= (base64), or =?UTF-8?Q?=C3=84pfel?= (quoted-printable).
Using a JSON array¶
Alternatively, the same actions can be defined as JSON array, if the notification is defined as part of the JSON body (see publish as JSON):
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl ntfy.sh
-d '{
"topic": "myhome",
"message": "You left the house. Turn down the A/C?",
"actions": [
{
"action": "view",
"label": "Open portal",
"url": "https://home.nest.com/",
"clear": true
},
{
"action": "http",
"label": "Turn down",
"url": "https://api.nest.com/",
"body": "{"temperature": 65}"
}
]
}'
The required/optional fields for each action depend on the type of the action itself. Please refer to view action, broadcast action, and http action for details.
Open website/app¶
Supported on:
The view action opens a website or app when the action button is tapped, e.g. a browser, a Google Maps location, or even a deep link into Twitter or a show ntfy topic. How exactly the action is handled depends on how Android and your desktop browser treat the links. Normally it'll just open a link in the browser.
Examples:
http:// or https:// will open your browser (or an app if it registered for a URL) mailto: links will open your mail app, e.g. mailto:[email protected] geo: links will open Google Maps, e.g. geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA ntfy:// links will open ntfy (see ntfy:// links), e.g. ntfy://ntfy.sh/stats twitter:// links will open Twitter, e.g. twitter://user?screen_name=.. ...
Here's an example using the X-Actions header:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "Somebody retweeted your tweet."
-H "Actions: view, Open Twitter, https://twitter.com/binwiederhier/status/1467633927951163392"
ntfy.sh/myhome
And the same example using JSON publishing:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl ntfy.sh
-d '{
"topic": "myhome",
"message": "Somebody retweeted your tweet.",
"actions": [
{
"action": "view",
"label": "Open Twitter",
"url": "https://twitter.com/binwiederhier/status/1467633927951163392"
}
]
}'
The view action supports the following fields:
Field Required Type Default Example Description action ✔️ string - view Action type (must be view) label ✔️ string - Turn on light Label of the action button in the notification url ✔️ URL - https://example.com URL to open when action is tapped clear -️ boolean false true Clear notification after action button is tapped Send Android broadcast¶
Supported on:
The broadcast action sends an Android broadcast intent when the action button is tapped. This allows integration into automation apps such as MacroDroid or Tasker, which basically means you can do everything your phone is capable of. Examples include taking pictures, launching/killing apps, change device settings, write/read files, etc.
By default, the intent action io.heckel.ntfy.USER_ACTION is broadcast, though this can be changed with the intent parameter (see below). To send extras, use the extras parameter. Currently, only string extras are supported.
Info
If you have no idea what this is, check out the automation apps section, which shows how to integrate Tasker and MacroDroid with screenshots. The action button integration is identical, except that you have to use the intent action io.heckel.ntfy.USER_ACTION instead.
Here's an example using the X-Actions header:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "Your wife requested you send a picture of yourself."
-H "Actions: broadcast, Take picture, extras.cmd=pic, extras.camera=front"
ntfy.sh/wifey
And the same example using JSON publishing:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl ntfy.sh
-d '{
"topic": "wifey",
"message": "Your wife requested you send a picture of yourself.",
"actions": [
{
"action": "broadcast",
"label": "Take picture",
"extras": {
"cmd": "pic",
"camera": "front"
}
}
]
}'
The broadcast action supports the following fields:
Field Required Type Default Example Description action ✔️ string - broadcast Action type (must be broadcast) label ✔️ string - Turn on light Label of the action button in the notification intent -️ string io.heckel.ntfy.USER_ACTION com.example.AN_INTENT Android intent name, default is io.heckel.ntfy.USER_ACTION extras -️ map of strings - see above Android intent extras. Currently, only string extras are supported. When publishing as JSON, extras are passed as a map. When the simple format is used, use extras.=. clear -️ boolean false true Clear notification after action button is tapped Send HTTP request¶
Supported on:
The http action sends a HTTP request when the action button is tapped. You can use this to trigger REST APIs for whatever systems you have, e.g. opening the garage door, or turning on/off lights.
By default, this action sends a POST request (not GET!), though this can be changed with the method parameter. The only required parameter is url. Headers can be passed along using the headers parameter.
Here's an example using the X-Actions header:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "Garage door has been open for 15 minutes. Close it?"
-H "Actions: http, Close door, https://api.mygarage.lan/, method=PUT, headers.Authorization=Bearer zAzsx1sk.., body={"action": "close"}"
ntfy.sh/myhome
And the same example using JSON publishing:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl ntfy.sh
-d '{
"topic": "myhome",
"message": "Garage door has been open for 15 minutes. Close it?",
"actions": [
{
"action": "http",
"label": "Close door",
"url": "https://api.mygarage.lan/",
"method": "PUT",
"headers": {
"Authorization": "Bearer zAzsx1sk.."
},
"body": "{"action": "close"}"
}
]
}'
The http action supports the following fields:
Field Required Type Default Example Description action ✔️ string - http Action type (must be http) label ✔️ string - Open garage door Label of the action button in the notification url ✔️ string - https://ntfy.sh/mytopic URL to which the HTTP request will be sent method -️ GET/POST/PUT/... POST ⚠️ GET HTTP method to use for request, default is POST ⚠️ headers -️ map of strings - see above HTTP headers to pass in request. When publishing as JSON, headers are passed as a map. When the simple format is used, use headers.=. body -️ string empty some body, somebody? HTTP body clear -️ boolean false true Clear notification after HTTP request succeeds. If the request fails, the notification is not cleared. Click action¶
Supported on:
You can define which URL to open when a notification is clicked. This may be useful if your notification is related to a Zabbix alert or a transaction that you'd like to provide the deep-link for. Tapping the notification will open the web browser (or the app) and open the website.
To define a click action for the notification, pass a URL as the value of the X-Click header (or its alias Click). If you pass a website URL (http:// or https://) the web browser will open. If you pass another URI that can be handled by another app, the responsible app may open.
Examples:
http:// or https:// will open your browser (or an app if it registered for a URL) mailto: links will open your mail app, e.g. mailto:[email protected] geo: links will open Google Maps, e.g. geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA ntfy:// links will open ntfy (see ntfy:// links), e.g. ntfy://ntfy.sh/stats twitter:// links will open Twitter, e.g. twitter://user?screen_name=.. ...
Here's an example that will open Reddit when the notification is clicked:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "New messages on Reddit"
-H "Click: https://www.reddit.com/message/messages"
ntfy.sh/reddit_alerts
Attachments¶
Supported on:
You can send images and other files to your phone as attachments to a notification. The attachments are then downloaded onto your phone (depending on size and setting automatically), and can be used from the Downloads folder.
There are two different ways to send attachments:
sending a local file via PUT, e.g. from ~/Flowers/flower.jpg or ringtone.mp3 or by passing an external URL as an attachment, e.g. https://f-droid.org/F-Droid.apk Attach local file¶
To send a file from your computer as an attachment, you can send it as the PUT request body. If a message is greater than the maximum message size (4,096 bytes) or consists of non UTF-8 characters, the ntfy server will automatically detect the mime type and size, and send the message as an attachment file. To send smaller text-only messages or files as attachments, you must pass a filename by passing the X-Filename header or query parameter (or any of its aliases Filename, File or f).
By default, and how ntfy.sh is configured, the max attachment size is 15 MB (with 100 MB total per visitor). Attachments expire after 3 hours, which typically is plenty of time for the user to download it, or for the Android app to auto-download it. Please also check out the other limits below.
Here's an example showing how to upload an image:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-T flower.jpg
-H "Filename: flower.jpg"
ntfy.sh/flowers
Here's what that looks like on Android:
Image attachment sent from a local file Attach file from a URL¶
Instead of sending a local file to your phone, you can use an external URL to specify where the attachment is hosted. This could be a Dropbox link, a file from social media, or any other publicly available URL. Since the files are externally hosted, the expiration or size limits from above do not apply here.
To attach an external file, simple pass the X-Attach header or query parameter (or any of its aliases Attach or a) to specify the attachment URL. It can be any type of file.
ntfy will automatically try to derive the file name from the URL (e.g https://example.com/flower.jpg will yield a filename flower.jpg). To override this filename, you may send the X-Filename header or query parameter (or any of its aliases Filename, File or f).
Here's an example showing how to attach an APK file:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-X POST
-H "Attach: https://f-droid.org/F-Droid.apk"
ntfy.sh/mydownloads
File attachment sent from an external URL Icons¶
Supported on:
You can include an icon that will appear next to the text of the notification. Simply pass the X-Icon header or query parameter (or its alias Icon) to specify the URL that the icon is located at. The client will automatically download the icon (unless it is already cached locally, and less than 24 hours old), and show it in the notification. Icons are cached locally in the client until the notification is deleted. Only JPEG and PNG images are supported at this time.
Here's an example showing how to include an icon:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-H "Icon: https://styles.redditmedia.com/t5_32uhe/styles/communityIcon_xnt6chtnr2j21.png"
-H "Title: Kodi: Resuming Playback"
-H "Tags: arrow_forward"
-d "The Wire, S01E01"
ntfy.sh/tvshows
Here's an example of how it will look on Android:
Custom icon from an external URL E-mail notifications¶
Supported on:
You can forward messages to e-mail by specifying an address in the header. This can be useful for messages that you'd like to persist longer, or to blast-notify yourself on all possible channels.
Usage is easy: Simply pass the X-Email header (or any of its aliases: X-E-mail, Email, E-mail, Mail, or e). Only one e-mail address is supported.
Since ntfy does not provide auth (yet), the rate limiting is pretty strict (see limitations). In the default configuration, you get 16 e-mails per visitor (IP address) and then after that one per hour. On top of that, your IP address appears in the e-mail body. This is to prevent abuse.
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-H "Email: [email protected]"
-H "Tags: warning,skull,backup-host,ssh-login"
-H "Priority: high"
-d "Unknown login from 5.31.23.83 to backups.example.com"
ntfy.sh/alerts
curl -H "Email: [email protected]" -d "You've Got Mail"
curl -d "You've Got Mail" "ntfy.sh/alerts?email=[email protected]"
Here's what that looks like in Google Mail:
E-mail notification E-mail publishing¶
Supported on:
You can publish messages to a topic via e-mail, i.e. by sending an email to a specific address. For instance, you can publish a message to the topic sometopic by sending an e-mail to [email protected]. This is useful for e-mail based integrations such as for statuspage.io (though these days most services also support webhooks and HTTP calls).
Depending on the server configuration, the e-mail address format can have a prefix to prevent spam on topics. For ntfy.sh, the prefix is configured to ntfy-, meaning that the general e-mail address format is:
ntfy-$[email protected]
If access control is enabled, and the target topic does not support anonymous writes, e-mail publishing won't work without providing an authorized access token or using SMTP AUTH PLAIN.
If you use access tokens, that will change the format of the e-mail's recipient address to
ntfy-$topic+$[email protected]
To use username/password, you can use SMTP PLAIN auth when authenticating to the ntfy server.
As of today, e-mail publishing only supports adding a message title (the e-mail subject). Tags, priority, delay and other features are not supported (yet). Here's an example that will publish a message with the title You've Got Mail to topic sometopic (see ntfy.sh/sometopic):
Publishing a message via e-mail Phone calls¶
Supported on:
You can use ntfy to call a phone and read the message out loud using text-to-speech. Similar to email notifications, this can be useful to blast-notify yourself on all possible channels, or to notify people that do not have the ntfy app installed on their phone.
Phone numbers have to be previously verified (via the web app), so this feature is only available to authenticated users (no anonymous phone calls). To forward a message as a voice call, pass a phone number in the X-Call header (or its alias: Call), prefixed with a plus sign and the country code, e.g. +12223334444. You may also simply pass yes as a value to pick the first of your verified phone numbers. On ntfy.sh, this feature is only supported to ntfy Pro plans.
Phone number verification in the web app
As of today, the text-to-speed voice used will only support English. If there is demand for other languages, we'll be happy to add support for that. Please open an issue on GitHub.
Info
You are responsible for the message content, and you must abide by the Twilio Acceptable Use Policy. This particularly means that you must not use this feature to send unsolicited messages, or messages that are illegal or violate the rights of others. Please read the policy for details. Failure to do so may result in your account being suspended or terminated.
Here's how you use it:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-u :tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
-H "Call: +12223334444"
-d "Your garage seems to be on fire. You should probably check that out."
ntfy.sh/alerts
Here's what a phone call from ntfy sounds like:
Audio transcript:
You have a notification from ntfy on topic alerts. Message: Your garage seems to be on fire. You should probably check that out. End message. This message was sent by user phil. It will be repeated up to three times.
Authentication¶
Depending on whether the server is configured to support access control, some topics may be read/write protected so that only users with the correct credentials can subscribe or publish to them. To publish/subscribe to protected topics, you can:
Use username & password via Basic auth, e.g. Authorization: Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk Use access tokens via Bearer/Basic auth, e.g. Authorization: Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 or use either with the auth query parameter, e.g. ?auth=QmFzaWMgZEdWemRIVnpaWEk2Wm1GclpYQmhjM04zYjNKaw
Warning
When using Basic auth, base64 only encodes username and password. It is not encrypting it. For your self-hosted server, be sure to use HTTPS to avoid eavesdropping and exposing your password.
Username + password¶
The simplest way to authenticate against a ntfy server is to use Basic auth. Here's an example with a user testuser and password fakepassword:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell 7+
PowerShell 5 and earlier
Python
PHP
curl
-u testuser:fakepassword
-d "Look ma, with auth"
https://ntfy.example.com/mysecrets
To generate the Authorization header, use standard base64 to encode the colon-separated : and prepend the word Basic, i.e. Authorization: Basic base64(:). Here's some pseudo-code that hopefully explains it better:
username = "testuser" password = "fakepassword" authHeader = "Basic " + base64(username + ":" + password) // -> Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk
The following command will generate the appropriate value for you on *nix systems:
echo "Basic $(echo -n 'testuser:fakepassword' | base64)"
Access tokens¶
In addition to username/password auth, ntfy also provides authentication via access tokens. Access tokens are useful to avoid having to configure your password across multiple publishing/subscribing applications. For instance, you may want to use a dedicated token to publish from your backup host, and one from your home automation system.
You can create access tokens using the ntfy token command, or in the web app in the "Account" section (when logged in). See access tokens for details.
Once an access token is created, you can use it to authenticate against the ntfy server, e.g. when you publish or subscribe to topics. Here's an example using Bearer auth, with the token tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell 7+
PowerShell 5 and earlier
Python
PHP
curl
-H "Authorization: Bearer tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2"
-d "Look ma, with auth"
https://ntfy.example.com/mysecrets
Alternatively, you can use Basic Auth to send the access token. When sending an empty username, the basic auth password is treated by the ntfy server as an access token. This is primarily useful to make curl calls easier, e.g. curl -u:tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2 ...:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-u :tk_AgQdq7mVBoFD37zQVN29RhuMzNIz2
-d "Look ma, with auth"
https://ntfy.example.com/mysecrets
Query param¶
Here's an example using the auth query parameter:
Command line (curl)
ntfy CLI
HTTP
JavaScript
Go
PowerShell
Python
PHP
curl
-d "Look ma, with auth"
"https://ntfy.example.com/mysecrets?auth=QmFzaWMgZEdWemRIVnpaWEk2Wm1GclpYQmhjM04zYjNKaw"
To generate the value of the auth parameter, encode the value of the Authorization header (see above) using raw base64 encoding (like base64, but strip any trailing =). Here's some pseudo-code that hopefully explains it better:
username = "testuser" password = "fakepassword" authHeader = "Basic " + base64(username + ":" + password) // -> Basic dGVzdHVzZXI6ZmFrZXBhc3N3b3Jk authParam = base64_raw(authHeader) // -> QmFzaWMgZEdWemRIVnpaWEk2Wm1GclpYQmhjM04zYjNKaw (no trailing =)
// If your language does not have a function to encode raw base64, simply use normal base64 // and REMOVE TRAILING "=" characters.
The following command will generate the appropriate value for you on *nix systems:
echo -n "Basic echo -n 'testuser:fakepassword' | base64 -w0" | base64 -w0 | tr -d '='
For access tokens, you can use this instead:
echo -n "Bearer faketoken" | base64 -w0 | tr -d '='
Advanced features¶ Message caching¶
Info
If Cache: no is used, messages will only be delivered to connected subscribers, and won't be re-delivered if a client re-connects. If a subscriber has (temporary) network issues or is reconnecting momentarily, messages might be missed.
By default, the ntfy server caches messages on disk for 12 hours (see message caching), so all messages you publish are stored server-side for a little while. The reason for this is to overcome temporary client-side network disruptions, but arguably this feature also may raise privacy concerns.
To avoid messages being cached server-side entirely, you can set X-Cache header (or its alias: Cache) to no. This will make sure that your message is not cached on the server, even if server-side caching is enabled. Messages are still delivered to connected subscribers, but since= and poll=1 won't return the message anymore.
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "X-Cache: no" -d "This message won't be stored server-side" ntfy.sh/mytopic curl -H "Cache: no" -d "This message won't be stored server-side" ntfy.sh/mytopic
Disable Firebase¶
Info
If Firebase: no is used and instant delivery isn't enabled in the Android app (Google Play variant only), message delivery will be significantly delayed (up to 15 minutes). To overcome this delay, simply enable instant delivery.
The ntfy server can be configured to use Firebase Cloud Messaging (FCM) (see Firebase config) for message delivery on Android (to minimize the app's battery footprint). The ntfy.sh server is configured this way, meaning that all messages published to ntfy.sh are also published to corresponding FCM topics.
If you'd like to avoid forwarding messages to Firebase, you can set the X-Firebase header (or its alias: Firebase) to no. This will instruct the server not to forward messages to Firebase.
Command line (curl) ntfy CLI HTTP JavaScript Go PowerShell Python PHP curl -H "X-Firebase: no" -d "This message won't be forwarded to FCM" ntfy.sh/mytopic curl -H "Firebase: no" -d "This message won't be forwarded to FCM" ntfy.sh/mytopic
UnifiedPush¶
Info
This setting is not relevant to users, only to app developers and people interested in UnifiedPush.
UnifiedPush is a standard for receiving push notifications without using the Google-owned Firebase Cloud Messaging (FCM) service. It puts push notifications in the control of the user. ntfy can act as a UnifiedPush distributor, forwarding messages to apps that support it.
When publishing messages to a topic, apps using ntfy as a UnifiedPush distributor can set the X-UnifiedPush header or query parameter (or any of its aliases unifiedpush or up) to 1 to disable Firebase. As of today, this option is mostly equivalent to Firebase: no, but was introduced to allow future flexibility. The flag additionally enables auto-detection of the message encoding. If the message is binary, it'll be encoded as base64.
Matrix Gateway¶
The ntfy server implements a Matrix Push Gateway (in combination with UnifiedPush as the Provider Push Protocol). This makes it easier to integrate with self-hosted Matrix servers (such as synapse), since you don't have to set up a separate push proxy (such as common-proxies).
In short, ntfy accepts Matrix messages on the /_matrix/push/v1/notify endpoint (see Push Gateway API), and forwards them to the ntfy topic defined in the pushkey of the message. The message will then be forwarded to the ntfy Android app, and passed on to the Matrix client there.
There is a nice diagram in the Push Gateway docs. In this diagram, the ntfy server plays the role of the Push Gateway, as well as the Push Provider. UnifiedPush is the Provider Push Protocol.
Info
This is not a generic Matrix Push Gateway. It only works in combination with UnifiedPush and ntfy.
Public topics¶
Obviously all topics on ntfy.sh are public, but there are a few designated topics that are used in examples, and topics that you can use to try out what authentication and access control looks like.
Topic User Permissions Description announcements * (unauthenticated) Read-only for everyone Release announcements and such stats * (unauthenticated) Read-only for everyone Daily statistics about ntfy.sh usage Limitations¶
There are a few limitations to the API to prevent abuse and to keep the server healthy. Almost all of these settings are configurable via the server side rate limiting settings. Most of these limits you won't run into, but just in case, let's list them all:
Limit Description Message length Each message can be up to 4,096 bytes long. Longer messages are treated as attachments. Requests By default, the server is configured to allow 60 requests per visitor at once, and then refills the your allowed requests bucket at a rate of one request per 5 seconds. Daily messages By default, the number of messages is governed by the request limits. This can be overridden. On ntfy.sh, the daily message limit is 250. E-mails By default, the server is configured to allow sending 16 e-mails per visitor at once, and then refills the your allowed e-mail bucket at a rate of one per hour. On ntfy.sh, the daily limit is 5. Phone calls By default, the server does not allow any phone calls, except for users with a tier that has a call limit. Subscription limit By default, the server allows each visitor to keep 30 connections to the server open. Attachment size limit By default, the server allows attachments up to 15 MB in size, up to 100 MB in total per visitor and up to 5 GB across all visitors. On ntfy.sh, the attachment size limit is 2 MB, and the per-visitor total is 20 MB. Attachment expiry By default, the server deletes attachments after 3 hours and thereby frees up space from the total visitor attachment limit. Attachment bandwidth By default, the server allows 500 MB of GET/PUT/POST traffic for attachments per visitor in a 24 hour period. Traffic exceeding that is rejected. On ntfy.sh, the daily bandwidth limit is 200 MB. Total number of topics By default, the server is configured to allow 15,000 topics. The ntfy.sh server has higher limits though.
These limits can be changed on a per-user basis using tiers. If payments are enabled, a user tier can be changed by purchasing a higher tier. ntfy.sh offers multiple paid tiers, which allows for much hier limits than the ones listed above.
List of all parameters¶
The following is a list of all parameters that can be passed when publishing a message. Parameter names are case-insensitive when used in HTTP headers, and must be lowercase when used as query parameters in the URL. They are listed in the table in their canonical form.
Info
ntfy supports UTF-8 in HTTP headers, but not every library or programming language does. If non-ASCII characters are causing issues for you in the title (i.e. you're seeing ? symbols), you may also encode any header as RFC 2047, e.g. =?UTF-8?B?8J+HqfCfh6o=?= (base64), or =?UTF-8?Q?=C3=84pfel?= (quoted-printable).
Parameter Aliases Description X-Message Message, m Main body of the message as shown in the notification X-Title Title, t Message title X-Priority Priority, prio, p Message priority X-Tags Tags, Tag, ta Tags and emojis X-Delay Delay, X-At, At, X-In, In Timestamp or duration for delayed delivery X-Actions Actions, Action JSON array or short format of user actions X-Click Click URL to open when notification is clicked X-Attach Attach, a URL to send as an attachment, as an alternative to PUT/POST-ing an attachment X-Markdown Markdown, md Enable Markdown formatting in the notification body X-Icon Icon URL to use as notification icon X-Filename Filename, file, f Optional attachment filename, as it appears in the client X-Email X-E-Mail, Email, E-Mail, mail, e E-mail address for e-mail notifications X-Call Call Phone number for phone calls X-Cache Cache Allows disabling message caching X-Firebase Firebase Allows disabling sending to Firebase X-UnifiedPush UnifiedPush, up UnifiedPush publish option, only to be used by UnifiedPush apps X-Poll-ID Poll-ID Internal parameter, used for iOS push notifications Authorization - If supported by the server, you can login to access protected topics Content-Type - If set to text/markdown, Markdown formatting is enabled Made with ❤️ by Philipp C. Heckel Made with Material for MkDocs