trigger exposed workflow on success of an API call

  • needtheanswers-1358150428910551262

    needtheanswers

    23 days ago

    Hi,
    maybe I’m overcomplicating things here, but I just can’t wrap my head around how to make this work. I´ve tried to illustrate it (hopefully this makes it a bit clearer). So I have a provider component with my apis. The api is wrapped in a workflow that is exposed in context so it can be called by the child components. Let´s assume that child component 1 runs the exposed workflow "W1" on load (that part is already working). Now comes the part that gives me a headache: ON SUCCESS of that api call I would like to call custom action "1". How do I wait for the success event? Events can´t be exposed and running another exposed workflow doesn´t work because based on what should I run it?

    I have multiple child components and everyone of them needs to call a different action. Also I don´t want every child component to have their individual api.

    Is there a way to accomplish this?
    Thanks
    1358150429090775220-image.png
  • lucasg-1358150966058160320

    Lucas G

    23 days ago

    Is there a reason why you can't just setup the appropriate workflows directly in the API's success flow?
  • If you don't always want to call it, you can set up a switch statement in the success flow to dictate whether or not to call it
  • That condition can be set by the workflow you're using to trigger the initial call
  • lucasg-1358151506800414802

    Lucas G

    23 days ago

    You could also set up multiple conditions to dictate which workflows to use (ie., action equals action1 then run custom action1 else if action equals false do nothing)
  • needtheanswers-1358154748062339423

    needtheanswers

    22 days ago

    I already tried setting workflows up in the API´s success flow but when I do it, my components (that get called by the custom actions) get rendered twice. That´s not the case when I call the actions on the child component level.
  • needtheanswers-1358155183024242718

    needtheanswers

    22 days ago

    I might wanna add that all my custom actions are basically the same - the only difference is that one renders the payments-component and another one renders the balances-component...
  • lucasg-1358155184928194722

    Lucas G

    22 days ago

    Then they are being triggered twice
  • Could be the call is set to auto-fetch then it is also being called onLoad or somethign similar
  • Also, sounds like the custom action could have a check for existing instances so it doesn't call things it doesn't need to
  • lucasg-1358156158283682124

    Lucas G

    22 days ago

    Either way, until workflows get callbacks, the only way to set it up right now is to do it directly in the success flow. If it is triggering twice then you'll have to go back to troubleshooting it
    👍1
  • And/or change your custom actions to check for existing instances
    👍1
  • needtheanswers-1358156665505185834

    needtheanswers

    22 days ago

    The call itself is a post request and not set to autofetch. It just returns different client secrets. The problem might really be the custom action that intializes stripe multiple times. I already tried to work on that earlier but it somewhere says that I need to intialize stripe for every component and I can´t call two components by using the same initialization. I´ll try to figure something out. Thanks for your help @Lucas G 🙏
  • lucasg-1358157454944370882

    Lucas G

    22 days ago

    Another workaround would be to have the API calls update an object in a variable (for example, clientSecret1: value1, clientSecret2, value2) then expose that variable via another context and when that changes then call the custom action.
  • It would hacky and honestly not ideal
  • But it could technically work
  • I'd avoid that though and just update the custom actions to check for existing instances
  • needtheanswers-1358160178549231739

    needtheanswers

    22 days ago

    That‘s a good idea tho! Definitely going to try that tomorrow but I‘ll also try to modify the custom actions.
    Once again thank you!!