Save in Third Party DB After Form Submit

Hi!

I have a function already to call a rest API to save the data to another database for integration purposes, I tested that javascript using a button, but I want to call it after the default submit 'OK' button is clicked, so if calling the rest API and is completed successfully then I want to submit the data and save it into SBM database but if the rest API returned an error I don't want to submit the data into the SBM database.


I read this in  the SBM JS documentation, but not sure if it will help in my scenario:

function customSubmitCallback()
{
// Prevent submit if Description field is empty
if ( IsFieldEmpty( "Description" ) )
{
ShowErrorDiv( true, "A description is required" );
return false;
}
else
{
ShowErrorDiv( false );
return true;
}
}
AddSubmitCallback( customSubmitCallback );


What is the best way to implement that in SBM?


Thanks!