After securing the loyalty of the northwestern Provinces to the May Revolution through elections of representatives to the Junta in Buenos Aires, Castelli sent General Antonio González Balcarce into the Upper Peru, but he was defeated at the battle of Cotagaita.