Setting the refresh interval for a hosted feature layer

128
1
01-16-2020 12:49 PM
Highlighted
New Contributor III

I have a project that will be adding hosted feature layers to a map, and eventually removing them and archiving the data for the layer. I would like to be able to set the refresh interval for the layer with the Python API so that the web map has a near live view of the data. I can set it manually in AGOL, but it will be a pain to have to manually do this for each layer. Does anyone know if it's possible to set the refresh interval using the Python API?

Reply
0 Kudos
1 Reply
Highlighted
New Contributor III

You can do it like this.

from arcgis.gis import GIS
import getpass

password = getpass.getpass("Enter password: ")

gis = GIS('org', 'username', password)
print("Connected to: {}\nConnected as: {}".format(
gis.properties.urlKey + "." + gis.properties.customBaseUrl,
gis.users.me.username))


webmap_item = gis.content.get('ce80541f342546319d99308cbeb9f675')
webmap_item

from arcgis.mapping import WebMap
webmap = WebMap(webmap_item)
webmap

json_key = 'refreshInterval'
for layer in webmap.layers:
print(layer.title)
if json_key in layer:
print('refreshInterval already exits with value {}'.format(layer[json_key]))
else:
print('Adding refreshInterval to the layer with value 2')
layer[json_key] = 2

webmap.update()
Reply
0 Kudos