[Tough problem to solve] Return data from API when this data is obtained from another backend workflow


James sends a POST API request to my Public Endpoint (lets name it “Backend workflow A”) in my Bubble App.

The request is asking for a list of things where each thing should have certain characteristics that can’t be filtered without using the action “Scheduling an API Workflow on a list”.

Therefore, Backend Workflow A contains a “Schedule an API workflow on a list” action.

The new Scheduled API workflow is called “Backend workflow B”.

In this workflow, lots of things are received one by one and filtered with the characteristics that James requieres.

Finally, the list is finished and ready to be sent to James.

The problem is, the final list was calculated on “Backend Workflow B”.

Using “Return data from API” action on “Backend workflow B” wouldn’t send the list to James because his API request was sent to “Backend workflow A” (which is my public endpoint).

How can I send the final list to James as a response to his API request? Any ideas would be highly appreciated. :raised_hands:

1 Like

Can you put an action on Backend Workflow A to Return Data From API only when a specific variable (yes/no) is yes and make all other actions on that workflow only run if the same variable is no. Then call the backend workflow a as the last step in backend workflow b while passing the yes variable and the data to be returned. And when James uses calls backend workflow a from the front end workflows make the variable no there. This way he will receive the data back.

Hi! Thanks for your reply.

If I call Backend workflow A from Backend workflow B, then I would be the caller, not James.

So I guess the returned data would return to me, not to James.

1 Like

I’m having this issue did you ever figure it out?

No, I think it is not possible at the moment

@pachocastillosr I’m a little puzzled.

In Backend Workflow A, are you using the ‘Schedule API workflow on a list’ action and using Backend Workflow B as the selected workflow?

If so, how is the final list calculated on Backend Workflow B? Wouldn’t this just return a bunch of responses back to Backend Workflow A - none of which individually are final, but together make the final list?

If Backend Workflow B is able to return the desired output using the ‘Return data from API’ action and all you need to do is just return it back to James, then this is possible.

In my situation, I make a request to Workflow A, it then calls Workflow B via an API call. Workflow B then makes an external API call which returns some ugly XML, which I then format into JSON and respond to Workflow A with a nice format that Bubble can understand. Workflow A now has the right data and this can be returned to the end user.

You can do this with the help of the API connector to call Backend Workflow B from Backend Workflow A. In terms of process, this is generally what happens;

  1. James calls backend workflow A
  2. Backend workflow A calls backend workflow B via an API call setup in the API connector
  3. Backend workflow B then executes, with the last action being ‘Return data from API’
  4. Backend workflow A then gets this response
  5. Backend workflow A uses the ‘Return data from API’ and its dynamic expression is the result of the API Connector API call
  6. James gets the response he needs

Basic instructions to set this up;

  1. Create both backend workflow A and B, both should have ‘Return data from API’ as their final action. Add whatever other actions you need the API workflows to perform before that.

  2. Jump into the API connector and create a new POST request using the URL for backend workflow B, including whatever parameters backend workflow B needs from backend workflow A to execute

I personally prefer to use the API functionality in a custom plugin because it lets you specify different URLs for dev and live which is useful for overall reliability but for the sake of this example, the API connector works too.

  1. Add the API call as an action for backend workflow A, making sure you pass the variables required

  2. Add ‘Return data from API’ action to backend workflow A, using the result of the API call as the response

1 Like

Hi! Thanks for your reply. I tried this but there is a problem.

James is expecting a list of things.

We are using “Schedule API workflow on a list” to start Backend Workflow B. This means that Backend Workflow B will run multiple times (one per each item of the list).

So, the result of Backend Workflow B will not be the result that James is expecting, it would just be a fraction of the full list that James is expecting.

We can’t send data to James every time that a Backend Workflow B cycle is completed, we should just send him data only once (the full list).

Yeah I thought that might be the case.

The only thing I can think of, which I haven’t validated, is the idea of building a semi-recursive workflow.

Here’s the idea;

  1. James triggers backend workflow A
  2. First step in backend workflow A is creating a data type that holds the relevant information, things to loop through, criteria and the final list of things that need to be returned to james (which will be empty)
  3. Trigger a custom event ‘process-list’, which processes the first thing to through, and then triggers a duplicate custom event ‘process-list2’, which is basically exactly the same (but needed because a custom event can’t trigger itself). These two custom events basically go back and forth until they run out of things to process.
  4. Because in theory custom events are synchronous - the return data from API action should wait until they are done.

Here’s some rough screenshots - in this scenario I’m looping through Job Companies.

This also might not work at all - enjoy!

I think I tried something like this as well previously and did not work. Fortunately, I found a way to filter the items I needed without the “Schedule API workflow on a list”, using advanced filters. So, although I never found a solution for the topic of this thread, I managed to solve my problem in another way.

Thanks for your help!