Shortly after the Napoleonic Wars ended, Ferdinand VII, recently restored to the throne in Spain, decided to send military forces to retake most of the northern South American colonies, which had established autonomous juntas and independent states.