I've found tons of topics about how to load a WMS layer in PyQGIS, but nothing about WMTS. In the GUI, adding a WMS or a WMTS layer is done by clicking the same button so I expect the syntax to be close, but I failed to figure it out entirely.
So I took this url (from this post) to make my testing :
It works if you try to add layers from this source using the GUI. I tried to copy the syntax that allows to add a WMS layer (so I added needed parameters like layers=, format=, style=) but my layer is never valid.
layer = QgsRasterLayer('url=http://opencache.statkart.no/gatekeeper/gk/gk.open_wmts?&layers=barentswatch_stedsnavn&Version=1.0.0&service=wmts&format=image/jpeg&styles=', 'anytitle', 'wms') layer.isValid() >> False
Does somebody see the mistake / know the trick (or where I can find documentation about it) ?