N
Novu5mo ago
Soumith

Hi Team,

Is there any way to Get Messages of a subscriber ordered by latest messages? If I send limit as 50 to getMessages API, it is giving me top 50 in chronological order but I'm looking for latest 50 messages to display on the app. Please let me know if that is possible.
17 Replies
Ask Inkeep
Ask Inkeep5mo ago
Hi @Soumith, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question. ----------------------------- While I generate an answer, here are some sources that might be helpful: * Get messages * Recipes * Backend SDK methods * Get in-app notification feed for a particular subscriber -----------------------------
Ask Inkeep
Ask Inkeep5mo ago
Answer Hi there, To retrieve the latest 50 messages for a subscriber using the Novu API, you can use the getMessages API endpoint. Currently, the API retrieves messages in chronological order, and there isn't a direct parameter to fetch them in reverse chronological order (from the newest to the oldest). However, you can still achieve this by fetching the messages as you currently do and then reversing the order in your application logic after retrieval. This means you would programmatically sort the messages by their timestamp in descending order once you have fetched them. If you're fetching messages and finding that they're not in the expected order, you might want to double-check the timestamp data and ensure that your sorting logic is functioning correctly. For more details on fetching messages, you can refer to the official documentation here: Get messages (1) . Let me know if you need further assistance!
Soumith
SoumithOP5mo ago
Thanks for the quick response, to fetch all notifications and reverse it programatically, I should know how many messages are there for that subscriber right? Is there any way I can skip the limit to get all messages? I see by default limit is 10.
Ask Inkeep
Ask Inkeep5mo ago
Got it. Tagging @Support for additional help. Got it. Tagging @Support for additional help.
Pawan Jain
Pawan Jain5mo ago
@Soumith There is small bug there, if you use any filter like channel or subscriberId, then it will return last created order
Soumith
SoumithOP5mo ago
@Pawan Jain In that case, is it possible to get all notifications without a limit(default 10) on it for specific subscriber? @Pawan Jain I would like to show recent 50 in-app messages for that specific subscriber on his dashboard, Is there any way we can achieve this?
Pawan Jain
Pawan Jain5mo ago
@Soumith you can use limit value as 50 for this. Are you facing any issue?
Soumith
SoumithOP5mo ago
@Pawan Jain Yes, but if I use limit as 50, I'm getting 50 oldest messages in chronological order. If I have 100 notifications for a subscriber and if I limit 50, it's giving me 1-50, but what I need is 50-100 so that I can sort it in reverse order even if it is in chronological order. Or, if there is an api to get all 100 messages without a limit that will help.
Pawan Jain
Pawan Jain5mo ago
@Soumith Checkout this video. I am using channel and subscriberId params with GET /messages api. It is returning response in most recent created order
Soumith
SoumithOP5mo ago
@Pawan Jain I'm using node sdk to get messages, does it make any difference? I have also checked it with curl call, I still get in chronological order.
Novu_Bot
Novu_Bot5mo ago
@Soumith, you just advanced to level 1!
Pawan Jain
Pawan Jain5mo ago
@Soumith Just want to check if you are using novu cloud or self hosting Novu?
Soumith
SoumithOP5mo ago
We are using self hosting Novu @Pawan Jain, did we have recent fix for this? Hi @Pawan Jain, Any update on this? @Pawan Jain Is there any way to get total number of messages(count) for specific subscriber?
Soumith
SoumithOP5mo ago
@Pawan Jain https://github.com/novuhq/novu/blob/9978bb7fb93f26d74de1ea8236a125583ed3938a/libs/dal/src/repositories/message/message.repository.ts#L705 getMessages API doesn't have sort: '-createdAt', so I guess it would return in chronological order right? I wonder how are you getting recent created order from postman?
GitHub
novu/libs/dal/src/repositories/message/message.repository.ts at 997...
Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations. - novuhq/novu
Ask Inkeep
Ask Inkeep5mo ago
Got it. Tagging @Support for additional help.
Pawan Jain
Pawan Jain5mo ago
@Soumith Sorry for delay in response. We will fix this. I see you are using self hosted version. Unfortunately, I will not be able to share any ETA when we will release new docker images
Soumith
SoumithOP5mo ago
Hi @Pawan Jain , Sounds good, is there any way we can monitor when you guys release new docker images? This is holding our launch so we would like to upgrade right away after they are released.
Want results from more Discord servers?
Add your server