Help with a Flow

So I am trying to build my first Flow and need some help. I’m trying to call an API based on the response from another API.

Here’s the process:
Call 1st API
Read response and if the status say success, call the 2nd API.

The only way I can get it to work is to insert a delay after calling the 1st API. It works, but not ideal because the response may at times take longer than my delay I have set…

Here is what I have so far:

<script is="dmx-flow" id="flow2" type="text/dmx-flow">[
  {
    run: {action: "{{api1.load()}}"}
  },
  {
    wait: {delay: 5000}
  },
  {
    condition: {
      if: "{{api1.data.status.contains(\"success\")}}",
      then: {
        steps: {
         run: {action: "{{api2.load()}}"}
        }
      },
      else: {
        steps: {
          bootbox.alert: {message: "failure"}
        }
      }
    }
  }
]</script>

How can I make the second call trigger conditionally on the first call, or am I going about this the wrong way?

Thanks,
Chris

You can’t call external page actions that are executed asynchronous and assume their data will be available on the next step of the flow.

Only flow actions can be used within the flow and their results will be available.

We already have a flow action for server connect and API call will be available soon.

2 Likes

See

Ok thanks. Any ideas maybe as to how I can accomplish this another way, or is adding the delay in the best for now?

Well if you just st need two api calls after each other trigger the second one load in the first one success event - don’t really need a flow for that

yeah I was gonna say just use an action script with a condition. If the first API returns a 200 for success or whatever, then have second api load based on the returning of that condition? Should be able to look at what is returned from the schema?

I will for sure try it out and see what happens. APIs are not something I know that much about.

Thanks for the suggestions.

So using On Success on the first API does trigger the second API, but I don’t see anywhere that I can trigger it based on a certain value returned in the response of the 1st one.
There is a column in the Schema of the 1st API called “Status”. I need to trigger the 2nd API if the value in Status is success or failure.

Here is the response form the 1st API.

image

See that entry called Status? If that says “Success” I need to trigger the 2nd API.

You should be able to do that by having them in the same server action and using a condition based on the result of the first API…