King Maha Vajiralongkorn - who spends much of his time in Germany - was cycling late at night with his entourage near Munich airport.
The boys - aged 13 and 14 - shot at him from the window of a house in the town of Erding on 10 June, prosecutors say.
It's not clear if they hit the king but no-one was injured.
King Vajiralongkorn, 64, took the throne last year following the death of his father.
"As of now it is not certain that the king himself was hit," a spokesman for the local prosecutor's office, Thomas Rauscher, told BBC Thai.
"All that is known is that the king was part of a group of cyclists and that shots were fired at this group."
He said shots were also fired later when the group drove past in the king's car.
"The total number of shots is as yet unknown. We know however that more than one shot was fired."
It's not clear if the boys knew who they were shooting at.
The 14-year-old is being investigated on suspicion of attempted bodily harm, although the king declined to press charges. The 13-year-old is too young to face prosecution under German laws.
"The king was not interested in taking any legal action against the boysâ€¦ But in Germany, it is not up to the victim to decide [about the charges]," said Mr Rauscher.
The monarch's personal guards are understood to have called the police.
The king has two villas on Lake Starnberg, about 60km (37.5 miles) away from Erding, Bild Zeitung reports.
He will not be formally crowned until some time after the cremation of his father, which is expected later this year.
Late King Bhumibol Adulyadej was widely seen as a pillar of stability during seven decades of political turmoil in Thailand.
But his son is yet to enjoy the same level of popularity, and has spent much of his life abroad.
Married and divorced three times, he has seven children. Most ordinary Thais know only a few details about who he is and how he lives his life.
But many will remember his interest in cycling. In 2015 thousands of Thai cyclists joined the then-crown prince in a ride through Bangkok in honour of his mother, Queen Sirikit.
It was the first event to be publicly led by the prince and served to underline that he was the undisputed heir to the throne.
The authorities in Germany say the King of Thailand was unhurt when two teenage boys shot at him in the dark with an air pistol.