[GH-ISSUE #1196] When subscribing to messages via an API using the raw stream, how should the messages be split in order to retrieve the latest ones? #845

Closed
opened 2026-05-07 00:28:07 +02:00 by BreizhHardware · 8 comments

Originally created by @BaeKey on GitHub (Oct 9, 2024).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1196

After reviewing the documentation, I couldn't find any query parameters that allow fetching the latest messages. I want to use iOS Shortcuts to retrieve the latest messages for a specified topic. However, using either /json or /sse, iOS Shortcuts currently can't parse the file content correctly. If I use the raw format, I'm unable to properly split the content. I have also found a similar issue to mine.

How to get the latest message of a topic in JSON format from the API?

Could you consider adding a filter parameter to retrieve the latest message, or advise me on how to correctly parse the messages from the raw format?

Originally created by @BaeKey on GitHub (Oct 9, 2024). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1196 <!-- STOP! This is not the right place to ask for help. Consider asking on Discord/Matrix instead. You'll usually get an answer sooner, and there are more people there to help! - Discord: https://discord.gg/cT7ECsZj9w - Matrix: https://matrix.to/#/#ntfy:matrix.org / https://matrix.to/#/#ntfy-space:matrix.org --> After reviewing the documentation, I couldn't find any query parameters that allow fetching the latest messages. I want to use iOS Shortcuts to retrieve the latest messages for a specified topic. However, using either /json or /sse, iOS Shortcuts currently can't parse the file content correctly. If I use the raw format, I'm unable to properly split the content. I have also found a similar issue to mine. [How to get the latest message of a topic in JSON format from the API?](https://github.com/binwiederhier/ntfy/issues/1185) Could you consider adding a filter parameter to retrieve the latest message, or advise me on how to correctly parse the messages from the raw format?
Author
Owner

@wunter8 commented on GitHub (Oct 10, 2024):

Here are the actions that worked for me. This will show a pop-up/alert/notification with the message of the most recent message sent to the topic

  1. Get contents of URL: https://ntfy.sh/mytopic/raw?poll=1
  2. Split text: Split "Contents of URL" by "New Lines" (make sure "Contents of URL" treats the URL response as "Text")
  3. Get item from list: Get "Last Item" from "Split Text"
  4. Show alert: "Item from list"
<!-- gh-comment-id:2403846307 --> @wunter8 commented on GitHub (Oct 10, 2024): Here are the actions that worked for me. This will show a pop-up/alert/notification with the `message` of the most recent message sent to the topic 1. Get contents of URL: https://ntfy.sh/mytopic/raw?poll=1 2. Split text: Split "Contents of URL" by "New Lines" (make sure "Contents of URL" treats the URL response as "Text") 3. Get item from list: Get "Last Item" from "Split Text" 4. Show alert: "Item from list"
Author
Owner

@BaeKey commented on GitHub (Oct 10, 2024):

Here are the actions that worked for me. This will show a pop-up/alert/notification with the message of the most recent message sent to the topic

  1. Get contents of URL: https://ntfy.sh/mytopic/raw?poll=1
  2. Split text: Split "Contents of URL" by "New Lines" (make sure "Contents of URL" treats the URL response as "Text")
  3. Get item from list: Get "Last Item" from "Split Text"
  4. Show alert: "Item from list"

Thank you for your explanation. However, when using the method of splitting 'Contents of URL' by 'New Lines,' sometimes when dealing with multi-line text, I encounter an issue where only the last line of the text is extracted, and I haven't been able to solve it.

<!-- gh-comment-id:2404022047 --> @BaeKey commented on GitHub (Oct 10, 2024): > Here are the actions that worked for me. This will show a pop-up/alert/notification with the `message` of the most recent message sent to the topic > > 1. Get contents of URL: https://ntfy.sh/mytopic/raw?poll=1 > 2. Split text: Split "Contents of URL" by "New Lines" (make sure "Contents of URL" treats the URL response as "Text") > 3. Get item from list: Get "Last Item" from "Split Text" > 4. Show alert: "Item from list" Thank you for your explanation. However, when using the method of splitting 'Contents of URL' by 'New Lines,' sometimes when dealing with multi-line text, I encounter an issue where only the last line of the text is extracted, and I haven't been able to solve it.
Author
Owner

@wunter8 commented on GitHub (Oct 10, 2024):

When I send multi-line text and read it back in the "raw" stream, it's collapsed onto one line, so it splits fine in the iOS Shortcut. Are you saying it doesn't collapse onto one line for you?

<!-- gh-comment-id:2404055880 --> @wunter8 commented on GitHub (Oct 10, 2024): When I send multi-line text and read it back in the "raw" stream, it's collapsed onto one line, so it splits fine in the iOS Shortcut. Are you saying it doesn't collapse onto one line for you?
Author
Owner

@BaeKey commented on GitHub (Oct 10, 2024):

When I send multi-line text and read it back in the "raw" stream, it's collapsed onto one line, so it splits fine in the iOS Shortcut. Are you saying it doesn't collapse onto one line for you?

This issue might be related to my code. When I use a Python script to automatically send clipboard content, I use the following code:

def send_clipboard(msg):
    requests.post("https://%s" % (URL),
                  data=msg.encode(encoding='utf-8'),
                  headers={
                      "Authorization": TOKEN if TOKEN != "-" else "",
                      "Title": CLIENTNAME
                  })

During testing, when sending multi-line text, the iOS Shortcut only receives the last line of text.

Thank you for your help. Perhaps I can fix this by modifying the request I’m sending.

<!-- gh-comment-id:2404064978 --> @BaeKey commented on GitHub (Oct 10, 2024): > When I send multi-line text and read it back in the "raw" stream, it's collapsed onto one line, so it splits fine in the iOS Shortcut. Are you saying it doesn't collapse onto one line for you? This issue might be related to my code. When I use a Python script to automatically send clipboard content, I use the following code: ```python def send_clipboard(msg): requests.post("https://%s" % (URL), data=msg.encode(encoding='utf-8'), headers={ "Authorization": TOKEN if TOKEN != "-" else "", "Title": CLIENTNAME }) ``` During testing, when sending multi-line text, the iOS Shortcut only receives the last line of text. Thank you for your help. Perhaps I can fix this by modifying the request I’m sending.
Author
Owner

@wunter8 commented on GitHub (Oct 11, 2024):

Hmm. I tested your script (using python 3.10). The message printed on two lines in the console and in the web app, but in the "raw" stream, it was collapsed onto one line for me. I was able to grab the whole "test message" in the iOS Shortcut.

import requests
URL = 'ntfy.sh/mytopic'
TOKEN = '-'
CLIENTNAME = 'test'

def send_clipboard(msg):
    requests.post("https://%s" % (URL),
                  data=msg.encode(encoding='utf-8'),
                  headers={
                      "Authorization": TOKEN if TOKEN != "-" else "",
                      "Title": CLIENTNAME
                      })

if __name__ == '__main__':
    send_clipboard('test\nmessage')
    print('test\nmessage')

This printed on two lines in the console and in the web app

<!-- gh-comment-id:2406492928 --> @wunter8 commented on GitHub (Oct 11, 2024): Hmm. I tested your script (using python 3.10). The message printed on two lines in the console and in the web app, but in the "raw" stream, it was collapsed onto one line for me. I was able to grab the whole "test message" in the iOS Shortcut. ```python3 import requests URL = 'ntfy.sh/mytopic' TOKEN = '-' CLIENTNAME = 'test' def send_clipboard(msg): requests.post("https://%s" % (URL), data=msg.encode(encoding='utf-8'), headers={ "Authorization": TOKEN if TOKEN != "-" else "", "Title": CLIENTNAME }) if __name__ == '__main__': send_clipboard('test\nmessage') print('test\nmessage') ``` This printed on two lines in the console and in the web app
Author
Owner

@BaeKey commented on GitHub (Oct 11, 2024):

Hmm. I tested your script (using python 3.10). The message printed on two lines in the console and in the web app, but in the "raw" stream, it was collapsed onto one line for me. I was able to grab the whole "test message" in the iOS Shortcut.

import requests
URL = 'ntfy.sh/mytopic'
TOKEN = '-'
CLIENTNAME = 'test'

def send_clipboard(msg):
    requests.post("https://%s" % (URL),
                  data=msg.encode(encoding='utf-8'),
                  headers={
                      "Authorization": TOKEN if TOKEN != "-" else "",
                      "Title": CLIENTNAME
                      })

if __name__ == '__main__':
    send_clipboard('test\nmessage')
    print('test\nmessage')

This printed on two lines in the console and in the web app

I copied this paragraph at random:

  Failed to create a virtual machine in vCenter: PBM error occurred during PreCreateCheckCallback: Connection refused. 
  dinghui.org has been viewed 402 times on the VMware tag.
  Failed to create a virtual machine via vCenter: PBM error occurred during PreCreateCheckCallback: Connection refused.
  
  Additionally, I found that migrating the virtual machine also cannot be completed.
  
  However, creating a virtual machine can be done on the ESXi host, so the idea is to check the services of vCenter.

When I send this, iOS Shortcut can only receive the last sentence.

<!-- gh-comment-id:2406678728 --> @BaeKey commented on GitHub (Oct 11, 2024): > Hmm. I tested your script (using python 3.10). The message printed on two lines in the console and in the web app, but in the "raw" stream, it was collapsed onto one line for me. I was able to grab the whole "test message" in the iOS Shortcut. > > ```python > import requests > URL = 'ntfy.sh/mytopic' > TOKEN = '-' > CLIENTNAME = 'test' > > def send_clipboard(msg): > requests.post("https://%s" % (URL), > data=msg.encode(encoding='utf-8'), > headers={ > "Authorization": TOKEN if TOKEN != "-" else "", > "Title": CLIENTNAME > }) > > if __name__ == '__main__': > send_clipboard('test\nmessage') > print('test\nmessage') > ``` > > This printed on two lines in the console and in the web app I copied this paragraph at random: ``` Failed to create a virtual machine in vCenter: PBM error occurred during PreCreateCheckCallback: Connection refused. dinghui.org has been viewed 402 times on the VMware tag. Failed to create a virtual machine via vCenter: PBM error occurred during PreCreateCheckCallback: Connection refused. Additionally, I found that migrating the virtual machine also cannot be completed. However, creating a virtual machine can be done on the ESXi host, so the idea is to check the services of vCenter. ``` When I send this, iOS Shortcut can only receive the last sentence.
Author
Owner

@wunter8 commented on GitHub (Jun 9, 2025):

@BaeKey ntfy version 2.12.0 includes a new ?since=latest query param that you can use to poll just the most recent message in any topic

<!-- gh-comment-id:2956905683 --> @wunter8 commented on GitHub (Jun 9, 2025): @BaeKey ntfy version 2.12.0 includes a new `?since=latest` query param that you can use to poll just the most recent message in any topic
Author
Owner

@BaeKey commented on GitHub (Jun 10, 2025):

@BaeKeyntfy 版本 2.12.0 包含一个新的?since=latest查询参数,您可以使用它来轮询任何主题中的最新消息

Okay, I will try it. Thank you very much.

<!-- gh-comment-id:2957392493 --> @BaeKey commented on GitHub (Jun 10, 2025): > [@BaeKey](https://github.com/BaeKey)ntfy 版本 2.12.0 包含一个新的`?since=latest`查询参数,您可以使用它来轮询任何主题中的最新消息 Okay, I will try it. Thank you very much.
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#845
No description provided.