/messages/findMessages remoteJid filter not working
Welcome!
- [x] Yes, I have searched for similar issues on GitHub and found none.
What did you do?
I discovered that the /messages/findMessages/${instanceKey} endpoint's filtering by remoteJid is not working as expected. When trying to fetch messages for a specific conversation using this endpoint with the remoteJid parameter in the request body, it doesn't properly filter the messages.
As a workaround, I had to:
- Use
/messages/fetch/${instanceKey}to get all messages - Filter the messages client-side by matching
remoteJid - Sort and limit the results manually
Example of the current workaround:
// Get all messages since Evolution API's findMessages filter by remoteJid doesn't work
const response = await this.makeRequest(`/messages/fetch/${instanceKey}`, 'GET');
const allMessages = await response.json();
// Filter messages for this conversation
const conversationMessages = allMessages.filter((msg: any) => {
const msgJid = msg.key?.remoteJid?.toLowerCase();
const targetJid = remoteJid.toLowerCase();
return msgJid === targetJid;
});
// Sort by timestamp and limit
const sortedMessages = conversationMessages
.sort((a: any, b: any) => (b.messageTimestamp || 0) - (a.messageTimestamp || 0))
.slice(0, limit);
What did you expect?
The /messages/findMessages/${instanceKey} endpoint should properly filter messages by the provided remoteJid parameter in the request body, returning only messages from that specific conversation.
What did you observe instead of what you expected?
The endpoint either:
- Returns all messages regardless of the
remoteJidparameter - Or returns an empty array
This forces us to fetch all messages and filter them client-side, which is less efficient and could cause performance issues with large message histories.
Screenshots/Videos
No response
Which version of the API are you using?
Latest (2.3.0)
What is your environment?
Docker
Other environment specifications
Docker
If applicable, paste the log output
No response
Additional Notes
This issue impacts applications that need to efficiently load conversation histories. The current workaround of fetching all messages and filtering client-side could cause performance issues, especially for instances with many messages or high message volume.
Potential fix suggestions:
- Fix the
remoteJidfiltering in the/messages/findMessages/${instanceKey}endpoint - Or document that filtering should be done client-side and update the API docs accordingly
- Or add a new endpoint specifically designed for efficient conversation message fetching
have you tried {{baseUrl}}/chat/findChats/{{instance}}
Isn't {{baseUrl}}/chat/findChats/{{instance}} to get chats of an instance? I was trying to get messages in a conversation (remoteJid). The api reference clearly mentions it in this endpoint /messages/findMessages/${instanceKey} (by stating remoteJid in the body), but this doesn't work.
Same issue here. I even tried to get more pages (according to Postman collection) but didn't get another response.
The same problem here with typebot
The same error here i get timeout
SOLUTION:
After so many test i did it. You need to keep the substring in remoteJid "s.whatsapp.net" to work. So the json will be so:
"where": { "key": { "remoteJid": "[email protected]" } } }
This a example of how it works in N8N to send to Evolution.
Api Reference: https://doc.evolution-api.com/v2/api-reference/chat-controller/find-messages
@joaosouz4dev @JhonTechBr @AleNicoMar @kuncoroatmojo
SOLUTION:
After so many test i did it. You need to keep the substring in remoteJid "s.whatsapp.net" to work. So the json will be so:
"where": { "key": { "remoteJid": "[email protected]" } } }
This a example of how it works in N8N to send to Evolution.
Api Reference: https://doc.evolution-api.com/v2/api-reference/chat-controller/find-messages
thank u