Broadly speaking, this is widely regarded amongst historians as not true at all, though most American schoolchildren are still taught it.
Mostly this is because American conventional airpower was so overwhelming in Japan that its effects were substantially interchangeable with the bomb. Before the atomic bombings, Secretary of War Henry Stimson (who chose Hiroshima and Nagasaki as targets) mentioned that America had literally run out of targets to (conventionally) bomb in Japan [0].
A more detailed summary of the "Bomb didn't cause surrender" argument is given in [1].
[0] http://www.doug-long.com/stimson5.htm , ctrl-F for "I was a little fearful that before we could get ready the Air Force might have Japan so thoroughly bombed out that the new weapon [the atomic bomb] would not have a fair background to show its strength."
[1] https://foreignpolicy.com/2013/05/30/the-bomb-didnt-beat-jap...
Yes, its military effects. (And humanitarian effects.)
But no, in political effect. If "war is politics carried on by other means" and the goal was to defeat Japanese Fascism, then you had to make sure it couldn't come back from the dead after a grudging surrender. That was IMHO the main lesson of Versailles. And it worked.
When people debate this issue, I find they tend to resort to a reductionist view of history and the players involved in order to justify their personal views of the US. The degree to which one is opposed to American cultural imperialism and military hegemony, or believes the US to be an evil state, tends to be the degree to which one believes the bombings had a nefarious purpose, or an ulterior motive. The whole thing has become a Rashomon style play of contradictory truths, except no one insisting on the order of events, motives or naming the culprit was actually there.
It seems more likely to me than not that the bombings didn't have only that one explicit purpose to the exclusion of the others, just as it seems unlikely to me that the bombings were either absolutely responsible or absolutely irrelevant to Japan's surrender.
> Indeed, we declared war on America and Britain out of our sincere desire to ensure Japan's self-preservation and the stabilization of East Asia, it being far from our thought either to infringe upon the sovereignty of other nations or to embark upon territorial aggrandizement.
They were specifically mentioned in emperor's address. Yes, they caused the surrender.
> Nagasaki and Hiroshima were not military targets
They were military targets. There was army HQ, troops stationed there, factories which were producing military goods.