binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
17.85k stars 697 forks source link

How to get the lastest message of a topic in JSON format from api? #1185

Open winteris opened 2 days ago

winteris commented 2 days ago

:question: Question

I just got a file named json.ndjson when I start a http request in safari and other internet explorer whit this URL: ntfy.sh/stats/json?poll=1 Exactly, I just want to get the lastest json string using a get http request in iOS shortcuts, but I can’t parse out the message. Can I get a JSON string directly with the api? https://docs.ntfy.sh/examples/ Examples in docs all are send and there is no a get example , can someone give me some help?

wunter8 commented 2 days ago

You can't get only the latest message using the API right now if you haven't been listening to the topic and tracking message IDs. /json?poll=1 is going to be your best option. Then just truncate the response/only look at the last line of the response

winteris commented 1 day ago

Thank you for your reply. I think I’ve followed the route you point out, but when I use /json?poll=1 to get all available messages, I got a json.ndjson file instead of a json string or text as the reponse., and then, I can’t parse out the message from the .ndjson file, in iOS shortcuts APP. I think It will more useul if I got a text type of reponse instead of a file one. Could it possible? Or need a feature request to move it on?

winteris commented 1 day ago

Got it finally! If I use ntfy.sh/topic/raw?poll=1, I’ll get a response in a text type. But I still wish the /json?poll=1 could support text response if it is possible.