Retrieving all messages from a conversation

Describe the problem/error/question

Hi there. I need to retrieve all messages from a conversation. I successfully retrieved all conversations using the page parameter and pagination options, but unfortunatelly, there is no page parameter in the API documentation for messages.

But there is a “before” parameter, that accespts a message-id. I’ve tried it, and it works. And when you get to the first message, if you use it’s id to make another API call, payload will be empty.

Now, i need to create the logic in n8n so that it makes as many API calls as necessary and store all the output in an array (in order). I have tried using the same logic as with pagination for retrieving all conversations, but I can’t seem to make it work even with the help of chatGPT.

When using the page parameter for conversations, all I had to do is update the page parameter using the following expression:
{{ $pageCount + 1 }}
And this would be the pagination condition to stop:
{{ $response.body.data.payload.isEmpty() }}

Now, I need to update the before parameter, using the id from the response’s first element. I thought it could be something like this:
{{ $response.body.data.payload[0].id }}
With the same stop condition:
{{ $response.body.data.payload.isEmpty() }}

But all I’m getting is the first “page” of the messages, it won’t make the loop.

Can anybody help me figure out how to do this?

Thanks in advance,
Javier

What is the error message (if any)?

No error, it’s just stoping after 1 API call

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • **n8n version: 1.60.1
  • **Database (default: SQLite): Postgress
  • **n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • **Operating system: Ubuntu server 22.04

Hi there. When pasting your workflow, can you put it in between Preformatted text? (The </> button). I wasn’t able to copy paste your workflow unfortunately.

Hi JayF! Done! Sorry, I’m new in the forum, and i hadn’t seen that buttom!
Now it’s correctly formated!

Thanks in advance,
Javi