Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all parameters for publishing in JSON body (including topic) #133

Closed
cmeis opened this issue Feb 7, 2022 · 4 comments
Closed

Allow all parameters for publishing in JSON body (including topic) #133

cmeis opened this issue Feb 7, 2022 · 4 comments
Labels
enhancement New feature or request server Relates to the main binary (server or client)

Comments

@cmeis
Copy link
Contributor

cmeis commented Feb 7, 2022

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.

@binwiederhier binwiederhier added enhancement New feature or request server Relates to the main binary (server or client) labels Feb 8, 2022
@binwiederhier
Copy link
Owner

binwiederhier commented 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

@binwiederhier
Copy link
Owner

binwiederhier commented 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.

@cmeis
Copy link
Contributor Author

cmeis commented Mar 15, 2022 via email

binwiederhier pushed a commit that referenced this issue Mar 15, 2022
@binwiederhier
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server Relates to the main binary (server or client)
Projects
None yet
Development

No branches or pull requests

2 participants