I’m placing 2 calls to the OpenAI api. The first is an action call just to create a thread (works fine). The second call uses the thread_id to get the list of messages (there are only 2 messages). When I initialize the second Action call in the api connector, the response is as expected. When I use the Action call in my workflow Bubble only seems to capture 1 of the messages…not the full list. I want to do this all on the server-side, so using Action calls. How can I get the full list, or is it some type of limitation for Action calls?

Can you share payload returned in API connector? Did you enable error and header chrckbox? You could also share the raw body after the call in run mode if this is the case

This is the json of the api connector initialization:

{
“object”: “list”,
“data”: [
{
“id”: “msg_TcHxxxxxxxxxxxxxxxxxx”,
“object”: “thread.message”,
“created_at”: 1728434291,
“assistant_id”: “asst_QKxxxxxxxwxxxxxxxxxx”,
“thread_id”: “thread_4Dxxxxxxxxxxxxxxxxxxxx”,
“run_id”: “run_Fdxxxxxxxxxxxxxxxxxx”,
“role”: “assistant”,
“content”: [
{
“type”: “text”,
“text”: {
“value”: “{"subject":"Great to Meet You, Jim!","body":"Hi Jim,\n\nIt was a pleasure meeting you! xxxxxxxx”}",
“annotations”:
}
}
],
“attachments”: ,
“metadata”: {}
},
{
“id”: “msg_JUxxxxxxxxxxxxxxxxxx”,
“object”: “thread.message”,
“created_at”: 1728434289,
“assistant_id”: null,
“thread_id”: “thread_4DAxxxxxxxxxxxxxxxxxx”,
“run_id”: null,
“role”: “user”,
“content”: [
{
“type”: “text”,
“text”: {
“value”: “Please provide xyz. Here are the parameters. xxxxxxxx”,
“annotations”:
}
}
],
“attachments”: ,
“metadata”: {}
}
],
“first_id”: “msg_TcHsxxxxxxxxxxxxxxx”,
“last_id”: “msg_JUzxxxxxxxxxxxxxxxxx”,
“has_more”: false
}

As you can see, the api connector returns both messages…the role = user and the role = assistant. In my workflow, only the role = user is returned.

Can you share your workflow settings

Backend API Workflow:

Actions

Action to create a run/thread

Using the thread_id from step 1, retrieve messages array
image

Then saving the result in my db just to observe.

image

With the :filtered role = assistant the result is blank. When I remove the :filtered it returns the message associated with the other message (i.e. role = user).

Also…when I first started this I was using a Data call on the front end, and I received the full response array. I did not want to run the api’s from the front end and moved to back-end using an Action call…and now my problem.

On your last screenshot, you are only saving the first item… I’m not sure exactly what you are trying to do.

There are only 2 messages in the response list…the message from the “user” and the message from the “assistant”. I only need the message from the “assistant”. When I remove the filter, I only get 1 message (the one from the “user”). When I’ve used the filtered call using a Data call, it correctly captures that message.

I understand what you are doing now. You need to inspect the response you got from step2. you could store the raw body json in a field. But this is only available if you activate the continue error and detect header in API connector. You will need to reconfigure your workflow after because this change the payload structure.

Ok will see if I can figure that out…thanks. Any idea why in Bubble the difference in response when using Data call vs Action call?

There’s no difference. The issue is probably in your response. But without seeing the response, it’s hard to investigate.

Figured it out. I had to put a delay between the initial call and the call to get the messages in order to give the OpenAI api time to generate the assistant message. It was only returning the 1 message because I was trying to retrieve the full thread before it had a chance to complete. Thanks for helping me think through things.

1 Like

Hey @Jici …just to round this out, since I had to use 2 api workflows in the backend (the second one after a 2 second delay), how can I get the result (or at least part of it in text format) of the 2nd api workflow back to my front end? The front end schedules api workflow1, api workflow1 schedules api workflow2. Then I need the result to get back to a text input in the front end.

In my research, I think I’m seeing that the only way to do it is to somehow setup a call in the api connector to my own backend api in order to get the value back to the front end…then use that internal call from my front end. I’m just trying to figure out how to get it to work with 2 workflow AND make it secure even though calling from browser side.