The resource-rich nation booked a $4.2 billion surplus last month as it enjoyed the impact of high commodity prices globally, although prices of some of its main products like palm oil, nickel, and natural gas have declined.

July's trade surplus is compared with Reuters' poll projection of $3.93 billion, and June's surplus of $5.09 billion.

Southeast Asia's largest economy, riding on the export boom since last year, recorded a trade surplus every month since May 2020. That helped boost its recovery from the impact of COVID-19 pandemic.

However, Statistics Indonesia has now warned the nation's export gains have been largely a reflection of rising prices, but export volume has remained relatively stagnant.

"The impressive growth of exports in January-July of 2022 was driven by a rise in commodity prices," said Setianto, deputy head of the bureau.

"This windfall could end if commodity prices return to normal. Because export volumes of our main commodites tend to be stagnant, this may be something that we need to pay attention in regards to our exports in coming months," he added.

July exports were up 32.03% on a yearly basis to $25.57 billion, compared with the poll's 29.73% growth forecast.

On a monthly basis, shipments of steel, tin and nickel fell.

Meanwhile, imports rose 39.86% to $21.35 billion, compared with an increase of 37.3% expected in the poll.

Statistics Indonesia also warned of the impact of rising tensions in the Taiwan Strait on trade, as China is Indonesia's biggest trade partner.

(Reporting by Stefanno Sulaiman, Gayatri Suroyo and Fransiska Nangoy; Editing by Kanupriya Kapoor and Uttaresh.V)

By Stefanno Sulaiman and Gayatri Suroyo