Adams held diplomatic posts for the duration of Madison's presidency, and he served as part of the American delegation that negotiated an end to the War of 1812. In 1817, newly-elected President James Monroe selected Adams as his Secretary of State. In that role, Adams negotiated the Adams–Onís Treaty, which provided for the American acquisition of Florida. Adams wanted to delay American recognition of the newly independent republics of Latin America that were breaking with Spanish imperialism, so as not to risk a war with Spain and its European allies. However, Andrew Jackson's military campaign in Florida, and Henry Clay's threats in Congress, forced Spain to cut a deal, which Adam negotiated successfully. While the other candidates based their candidacies on their long tenure as congressmen, ambassadors, or members of the cabinet, Jackson's appeal rested on his military service, especially in the Battle of New Orleans. The congressional nominating caucus had decided upon previous Democratic-Republican presidential nominees, but it had become largely discredited by 1824.