quality:correction, stylistic:tone
Course of the war

After the initial skirmishes, Taylor and much of his army marched away from the river to secure the supply line, leaving a makeshift base, Fort Texas. On the way back to the Rio Grande, Mexican forces under General Mariano Arista attempted to block Taylor's way as other troops laid siege to Fort Texas, forcing the U.S. Army general to the attack if he hoped to relieve the fort. In the Battle of Palo Alto, the first major engagement of the war, Taylor's troops forced Arista's from the field, suffering only four dead to hundreds for the Mexicans. The next day, Taylor led the army to victory in the Battle of Resaca de la Palma, putting the Mexican Army to rout. The early successes boosted support for the war, which despite the lopsided votes in Congress, had deeply divided the nation. Many Northern Whigs opposed the war, as did others; they felt Polk had used patriotism to manipulate the nation into fighting a war, the goal of which was to give slavery room to expand.

Polk distrusted the two senior officers, Major General Winfield Scott and Taylor, as both were Whigs, and would have replaced them with Democrats, but felt Congress would not approve it. He offered Scott the position of top commander in the war, which the general accepted. Polk and Scott already knew and disliked each other: the President made the appointment despite the fact that Scott had sought his party's presidential nomination for the 1840 election. Polk came to believe that Scott was too slow in getting himself and his army away from Washington and to the Rio Grande, and was outraged to learn Scott was using his influence in Congress to defeat the administration's plan to expand the number of generals. The news of Taylor's victory at Resaca de la Palma arrived then, and Polk decided to have Taylor take command in the field, and Scott to remain in Washington. Polk also ordered Commodore Conner to allow Antonio López de Santa Anna to return to Mexico from his exile in Havana, thinking that he would negotiate a treaty ceding territory to the U.S. for a price. Polk sent representatives to Cuba for talks with Santa Anna.

Polk sent an army expedition led by Stephen W. Kearny towards Santa Fe, to territory beyond the original claims in Texas. In 1845, Polk, fearful of French or British intervention, had sent Lieutenant Archibald H. Gillespie to California with orders to foment a pro-American rebellion that could be used to justify annexation of the territory. After meeting with Gillespie, Army captain John C. Frémont led settlers in northern California to overthrow the Mexican garrison in Sonoma in what became known as the Bear Flag Revolt. In August 1846, American forces under Kearny captured Santa Fe, capital of the province of New Mexico, without firing a shot. Almost simultaneously, Commodore Robert F. Stockton landed in Los Angeles and proclaimed the capture of California. After American forces put down a revolt, the United States held effective control of New Mexico and California. Nevertheless, the Western theater of the war would prove to be a political headache for Polk, since a dispute between Frémont and Kearny led to a break between Polk and the powerful Missouri senator (and father-in-law of Frémont), Thomas Hart Benton.

The initial public euphoria over the victories at the start of the war slowly dissipated. In August 1846, Polk asked Congress to appropriate $2 million (~$ 60.7 million in 2023) as a down payment for the potential purchase of Mexican lands. Polk's request ignited opposition, as he had never before made public his desire to annex parts of Mexico (aside from lands claimed by Texas). It was unclear whether such newly acquired lands would be slave or free, and there was fierce and acrimonious sectional debate. A freshman Democratic Congressman, David Wilmot of Pennsylvania, previously a firm supporter of Polk's administration, offered an amendment to the bill, the Wilmot Proviso, that would ban slavery in any land acquired using the money. The appropriation bill, with the Wilmot Proviso attached, passed the House, but died in the Senate. This discord cost Polk's party, with Democrats losing control of the House in the 1846 elections. In early 1847, though, Polk was successful in passing a bill raising further regiments, and he also finally won approval for the appropriation.

To try to bring the war to a quick end, in July 1846 Polk considered supporting a potential coup led by the exiled Mexican former president, General Antonio López de Santa Anna, with the hope that Santa Anna would sell parts of California. Santa Anna was in exile in Cuba, still a colony of Spain. Polk sent an envoy to have secret talks with Santa Anna. The U.S. Consul in Havana, R.B. Campbell, began seeking a way to engage with Santa Anna. A U.S. citizen of Spanish birth, Col. Alejandro José Atocha, knew Santa Anna and acted initially as an intermediary. Polk noted his contacts with Atocha in his diary, who said that Santa Anna was interested in concluding a treaty with the U.S. gaining territory while Mexico received payment that would include settling its debts. Polk decided that Atocha was untrustworthy and sent his own representative, Alexander Slidell Mackenzie, (a relative of John Slidell) to meet with Santa Anna. Mackenzie told Santa Anna that Polk wished to see him in power and that if they came to an agreement that the U.S. naval blockade would be lifted briefly to allow Santa Anna to return to Mexico. Polk requested $2 million from Congress to be used to negotiate a treaty with Mexico or payment to Mexico before a treaty was signed. The blockade was indeed briefly lifted and Santa Anna returned to Mexico, not to head a government that would negotiate a treaty with the U.S., but rather to organize a military defense of his homeland. Santa Anna gloated over Polk's naïveté; Polk had been "snookered" by Santa Anna. Instead of coming to a negotiated settlement with the U.S., Santa Anna mounted a defense of Mexico and fought to the bitter end. "His actions would prolong the war for at least a year, and more than any other single person, it was Santa Anna who denied Polk's dream of short war."

This caused Polk to harden his position on Mexico, and he ordered an American landing at Veracruz, the most important Mexican port on the Gulf of Mexico. From there, troops were to march through Mexico's heartland to Mexico City, which it was hoped would end the war. Continuing to advance in northeast Mexico, Taylor defeated a Mexican army led by Ampudia in the September 1846 Battle of Monterrey, but allowed Ampudia's forces to withdraw from the town, much to Polk's consternation. Polk believed Taylor had not aggressively pursued the enemy and offered command of the Veracruz expedition to Scott.

The lack of trust Polk had in Taylor was returned by the Whig general, who feared the partisan president was trying to destroy him. Accordingly, Taylor disobeyed orders to remain near Monterrey. In March 1847, Polk learned that Taylor had continued to march south, capturing the northern Mexican town of Saltillo. Continuing beyond Saltillo, Taylor's army fought a larger Mexican force, led by Santa Anna, in the Battle of Buena Vista. Initial reports gave the victory to Mexico, with great rejoicing, but Santa Anna retreated. Mexican casualties were five times that of the Americans, and the victory made Taylor even more of a military hero in the American public's eyes, though Polk preferred to credit the bravery of the soldiers rather than the Whig general.

The U.S. changed the course of the war with its invasion of Mexico's heartland through Veracruz and ultimately the capture of Mexico City, following hard fighting. In March 1847, Scott landed in Veracruz, and quickly won control of the city. The Mexicans expected that yellow fever and other tropical diseases would weaken the U.S. forces. With the capture of Veracruz, Polk dispatched Nicholas Trist, Buchanan's chief clerk, to accompany Scott's army and negotiate a peace treaty with Mexican leaders. Trist was instructed to seek the cession of Alta California, New Mexico, and Baja California, recognition of the Rio Grande as the southern border of Texas, and U.S. access across the Isthmus of Tehuantepec. Trist was authorized to make a payment of up to $30 million in exchange for these concessions.

In August 1847, as he advanced towards Mexico City, Scott defeated Santa Anna at the Battle of Contreras and the Battle of Churubusco. With the Americans at the gates of Mexico City, Trist negotiated with commissioners, but the Mexicans were willing to give up little. Scott prepared to take Mexico City, which he did in mid-September. In the United States, a heated political debate emerged regarding how much of Mexico the United States should seek to annex, Whigs such as Henry Clay arguing that the United States should only seek to settle the Texas border question, and some expansionists arguing for the annexation of all of Mexico. War opponents were also active; Whig Congressman Abraham Lincoln of Illinois introduced the "exact spot" resolutions, calling on Polk to state exactly where American blood had been shed on American soil to start the war, but the House refused to consider them.