It was the first decline in Canada's exports in 2022 and the first decline in imports since January.

As a result, the country's trade surplus with the world narrowed to C$4.05 billion ($3.07 billion) from a downwardly revised C$4.88 billion surplus in June. Analysts had forecast a surplus of C$3.80 billion.

The value of exports has risen by almost a fifth this year, mainly driven by higher prices, but a sharp decrease in prices drove export values down in July, Statistics Canada said.

Exports of consumer goods decreased 14.3% in July, while energy products were down 4.2%, data showed. By volume, total exports rose 1.7%, a third consecutive monthly increase.

Imports fell to C$64.2 billion. Consumer goods imports declined for the third consecutive month, with decreases observed in most subcategories, Statistics Canada said.

The Canadian dollar was trading at 1.3185 to the greenback, or 75.84 U.S. cents.

($1 = 1.3185 Canadian dollars)

(Reporting by Ismail Shakil and Dale Smith in Ottawa; Editing by Mark Porter)