I answered a very similar question a year ago. I hope it helps.
https://www.reddit.com/r/AskHistorians/comments/gdzrh5/what_role_did_spain_play_in_the_us_war_of/fpklmym