Answer:
The United States went to war with Mexico in 1846-1848, during the presidency of James K. Polk. The war was primarily fought over border disputes, specifically over whether Texas, which had recently been annexed by the United States, included the Rio Grande or the Nueces River as its southern boundary.
The United States government justified the war on a number of grounds. First, President Polk claimed that Mexico had "invaded our territory and shed American blood upon American soil" by crossing the Rio Grande and attacking American troops stationed in the disputed territory. This claim was disputed by some at the time, and many historians believe that the American troops were actually in territory claimed by Mexico.
Second, the United States government argued that Mexico had refused to negotiate a settlement to the border dispute, and had rejected a U.S. offer to purchase the disputed territory. This offer was made by Polk's envoy, John Slidell, who was sent to Mexico City in late 1845 to negotiate a settlement. When the Mexican government refused to receive Slidell, Polk used this as a pretext for war.
Third, some Americans believed in the idea of "manifest destiny," which held that the United States was destined to expand its territory and spread its influence throughout North America. The war with Mexico was seen by some as a way to fulfill this destiny.
Overall, the United States government justified the war with Mexico as a response to a Mexican invasion of American territory, as a way to settle a border dispute, and as a means of fulfilling America's manifest destiny. However, these justifications were controversial at the time, and many Americans and politicians opposed the war, arguing that it was unjust and aggressive.