While building an application on Appsmith, how do I run the second API when the first API passes?
2 Likes
The Action run
signature has support for this functionality
{{
Api1.run(
(response) => {
/* onSuccess of Api1 */
},
(response) => {
/* onError of Api1 */
},
)
}}
You can either run a new action, trigger a toast message or run any other trigger based functions from inside this callback. One caveat is that you do not have access to variables defined out side the callback over here (as it is with normal js) since the callbacks are run in a different context. Instead you can send in extra params as an object in the 3rd argument of the run function.
{{
const myConst = "Request was successful";
Api1.run(
(response, params) => {
showAlert(params.message, "success");
/* onSuccess of Api1 */
},
(response, params) => {
/* onError of Api1 */
},
{ message: myConst },
)
}}
3 Likes