The U.S. wanted Texas, and the Mexicans demurred. Texas had gained its independence from Mexico in 1836. There were some territorial issues and President Polk ordered General Zachary Taylor and his army into Texas. The Treaty of Guadalupe Hidalgo laid down the Rio Grande boundary. The U.S. got New Mexico and California, and shelled out $15 mil to Mexico.

from James K. Polk's Inaugural Address, March 4, 1845:

None can fail to see the danger to our safety and future peace if Texas remains an independent state or becomes an ally or dependency of some foreign nation more powerful than herself. Is there one among our citizens who would not prefer perpetual peace with Texas to occasional wars, which so often occur between bordering independent nations? Is there one who would not prefer free intercourse with her to high duties on all our products and manufactures which enter her ports or cross her frontiers? Is there one who would not prefer an unrestricted communication with her citizens to the frontier obstructions which must occur if she remains out of the Union? Whatever is good or evil in the local institutions of Texas will remain her own whether annexed to the United States or not. None of the present States will be responsible for them any more than they are for the local institutions of each other. They have confederated together for certain specified objects. Upon the same principle that they would refuse to form a perpetual union with Texas because of her local institutions our forefathers would have been prevented from forming our present Union. Perceiving no valid objection to the measure and many reasons for its adoption vitally affecting the peace, the safety, and the prosperity of both countries, I shall on the broad principle which formed the basis and produced the adoption of our Constitution, and not in any narrow spirit of sectional policy, endeavor by all constitutional, honorable, and appropriate means to consummate the expressed will of the people and Government of the United States by the reannexation of Texas to our Union at the earliest practicable period.