[GH-ISSUE #133] Allow all parameters for publishing in JSON body (including topic) #111

Closed
opened 2026-05-07 00:20:06 +02:00 by BreizhHardware · 4 comments

Originally created by @cmeis on GitHub (Feb 7, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/133

A generic way to publish via POST with JSON body (parameters like in URL parameters and HTTP headers) would be fantastic

As @binwiederhier wrote somewhere else something like this:

curl -d '{
  "topic": "mytopic",
  "message": "This is a message",
  "title": "My title"
}' ntfy.sh

Regarding the question "That's not a bad idea, though I'm not sure I see the benefit over the other publishing methods.":
The concrete use case is an access control system (like in "smart door lock") that has webhooks, but doesn't allow for parameters in the URL. So if I want to post to different topics using a variable there (indicating the door opened for example), I can only do this in the request body.
Right now I solved it by routing the notification from the access control system over a NodeRED instance, which is relaying it to ntfy after massaging body and header to fit.

I hope that's a clear enough usage case. If it's not too hard to implement, this would make sending notifications via ntfy even more versatile. I suppose there would have to be a kind of "universal topic" to post this to, like "ntfy.sh/publish", "ntfy.sh/api/publish" or the like.

Originally created by @cmeis on GitHub (Feb 7, 2022). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/133 A generic way to publish via POST with JSON body (parameters like in URL parameters and HTTP headers) would be fantastic As @binwiederhier wrote somewhere else something like this: ``` curl -d '{ "topic": "mytopic", "message": "This is a message", "title": "My title" }' ntfy.sh ``` Regarding the question "That's not a bad idea, though I'm not sure I see the benefit over the other publishing methods.": The concrete use case is an access control system (like in "smart door lock") that has webhooks, but doesn't allow for parameters in the URL. So if I want to post to different topics using a variable there (indicating the door opened for example), I can only do this in the request body. Right now I solved it by routing the notification from the access control system over a NodeRED instance, which is relaying it to ntfy after massaging body and header to fit. I hope that's a clear enough usage case. If it's not too hard to implement, this would make sending notifications via ntfy even more versatile. I suppose there would have to be a kind of "universal topic" to post this to, like "ntfy.sh/publish", "ntfy.sh/api/publish" or the like.
BreizhHardware 2026-05-07 00:20:06 +02:00
Author
Owner

@binwiederhier commented on GitHub (Mar 15, 2022):

I think the feature is sound and easy to implement, though I don't quite know what the API would look like. If there is a universal topic as you say it's easy, but if you want to also publish to the individual topics it's kinda tricky.

Here are a few options:

Request body is assumed to be a JSON request with a well-formed message. Options for endpoint names:

Option 1a:

curl -d '{ "message": "hi", "title": "ho" }' ntfy.sh/mytopic?as=message

Option 1b:

curl -d '{ .. same as above ...}' ntfy.sh/mytopic?body=json

Option 1c:

curl -d '{ .. same as above ...}' ntfy.sh/mytopic/json

Option 1d:

curl -d '{ .. same as above ...}' ntfy.sh/mytopic/message

Option 1e:

curl -d '{ .. same as above ...}' -H "Content-Type: application/json" ntfy.sh/mytopic

Option 1f (topic in the body JSON):

curl -d '{ "topic": "mytopic", ... }' ntfy.sh
<!-- gh-comment-id:1068376950 --> @binwiederhier commented on GitHub (Mar 15, 2022): I think the feature is sound and easy to implement, though I don't quite know what the API would look like. If there is a universal topic as you say it's easy, but if you want to also publish to the individual topics it's kinda tricky. Here are a few options: Request body is assumed to be a JSON request with a well-formed message. Options for endpoint names: Option 1a: ``` curl -d '{ "message": "hi", "title": "ho" }' ntfy.sh/mytopic?as=message ``` Option 1b: ``` curl -d '{ .. same as above ...}' ntfy.sh/mytopic?body=json ``` Option 1c: ``` curl -d '{ .. same as above ...}' ntfy.sh/mytopic/json ``` Option 1d: ``` curl -d '{ .. same as above ...}' ntfy.sh/mytopic/message ``` Option 1e: ``` curl -d '{ .. same as above ...}' -H "Content-Type: application/json" ntfy.sh/mytopic ``` Option 1f (topic in the body JSON): ``` curl -d '{ "topic": "mytopic", ... }' ntfy.sh ```
Author
Owner

@binwiederhier commented on GitHub (Mar 15, 2022):

I think option 1f (universal endpoint) is the only one I truly like, since it's short and doesn't need a super weird parameter to identify that the body is a JSON message blob. It is kinda tricky to implement though I think.

<!-- gh-comment-id:1068378613 --> @binwiederhier commented on GitHub (Mar 15, 2022): I think option 1f (universal endpoint) is the only one I truly like, since it's short and doesn't need a super weird parameter to identify that the body is a JSON message blob. It is kinda tricky to implement though I think.
Author
Owner

@cmeis commented on GitHub (Mar 15, 2022):

Yeah, 1f would be my favourite, too....

Am 15. März 2022, 20:26, um 20:26, "Philipp C. Heckel" @.***> schrieb:

I think option 1f (universal endpoint) is the only one I truly like,
since it's short and doesn't need a super weird parameter to identify
that the body is a JSON message blob.

--
Reply to this email directly or view it on GitHub:
https://github.com/binwiederhier/ntfy/issues/133#issuecomment-1068378613
You are receiving this because you authored the thread.

Message ID: @.***>

<!-- gh-comment-id:1068380354 --> @cmeis commented on GitHub (Mar 15, 2022): Yeah, 1f would be my favourite, too.... Am 15. März 2022, 20:26, um 20:26, "Philipp C. Heckel" ***@***.***> schrieb: >I think option 1f (universal endpoint) is the only one I truly like, >since it's short and doesn't need a super weird parameter to identify >that the body is a JSON message blob. > >-- >Reply to this email directly or view it on GitHub: >https://github.com/binwiederhier/ntfy/issues/133#issuecomment-1068378613 >You are receiving this because you authored the thread. > >Message ID: ***@***.***>
Author
Owner

@binwiederhier commented on GitHub (Mar 16, 2022):

This is done and will be released with the next server release

<!-- gh-comment-id:1069414778 --> @binwiederhier commented on GitHub (Mar 16, 2022): This is done and will be released with the next server release
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#111
No description provided.