Use external API response in logic for confirmation page

Hi, on my site I’m using the gform_after_submission hook to post the entry fields of the form to an external API URL to create a lead. This hook fires after redirect to a confirmation page. A user would always see the thank you page first. The API request follows after that and can fail.
I would like to use a different approach where I post the API request first, get the response and with a succesful response redirect to the thank you page. With an error response, I would like to redirect the user to an altnerative thank you page.
Is there a way to do this? Could I store a part of the API response (the error message) as a variable that I can use in the confirmation logic for instance? Maybe using the gform_pre_submission hook? And how would I do that?