It started 25 years earlier. Mexico wins independence from Spain in 1821 and after a brief period as a monarchy becomes a Republic in 1824.
The northern region in the then extant republic of Mexico was subject to Native American raids. In an effort to try to stem this the Mexican government sponsored immigration from the United States to the Mexican province of Texas. So far, so good.
Starting in 1834, several things happened in fairly rapid succession. Santa Anna eliminated the state legislature and gave himself dictatorial power. The US offered to purchase Texas from Mexico. The settlers in Texas, claiming that they were receiving none of the benefits of government were refusing to pay taxes to that government. Santa Anna repealed the agreement, refusing to allow additional settlers to Texas. By late 1835 Texas rebelled from Mexico.
In the end, Texas won de-facto independence of Mexico following the Battle of San Jacinto in 1836. However, Mexico never formally recognized its independence, still considering Texas to be a part of Mexico.
This continued until Texas agreed to annexation by the United States, becoming the 28th State in 1845. Newly elected President Polk, during this period, made an offer to buy disputed land between the Rio Grande and the Nueces rivers from Mexico. The offer was rejected. In early 1846 the new Mexican President Paredes included in his inaugural address a claim to land all the way to the Sabine river which marked the border between Texas and Louisianna. Polk then ordered Major General Zachary Taylor into the disputed territories, where a portion of Taylor’s forces, a scouting detail of 80 men led by Seth Thornton, were attacked and defeated in an ambush by an overwhelming force (1600 strong) of Mexican troops.
Word of this attack on and defeat of American troops in the disputed territories made its way back to Washington where, on May 11, 1846 President James K. Polk asked Congress for a declaration of war.
Two days later, the declaration was granted, officially beginning the Mexican War. The end result of that war won for the US the territory that would eventually become California, Nevada, Utah, most of Arizona, New Mexico, and Colorado, and parts of Texas, Kansas, Oklahoma, and Wyoming. (The Later Gadsden Purchase would obtain for the US the rest of Arizona and New Mexico–thus finalizing the outline of the Continental United States, which is a funny nomenclature considering that Alaska is part of the same continent.)