Hello Atma,
A year after solving this issue, I am in the situation where I need to update the urls in a WebMap and cannot find a good way to do it. I am using the Python API 1.4 but have not found any way to update an Item or a WebMap contents via Json, and do not understand what Charlie (user cwarewa) meant by "I then read that into the web map object for the new web map and now the features show up."
I tried getting the json contents from a template web map with 'get_data()' as you described here, and the used the updated json for the itemdict parameter on a new Item object in addition to the itemid of a newly created, empty WebMap but the map remained empty. As far as I can see, the update function on the WebMap object is only for updating the item info and metadata, is that correct?
I also tried using the rest endpoint "update" as explained in this GeoNet question and in the Docs but I get an error with the message "Item does not exist or is inaccessible" every time. Here's the section of code where I want to update the urls in the WebMap (token is created using same portal and credentials as the target_gis object):
# clone the template webmap
template_WebMap = source_gis.content.get(templateWebMapId)
result_WebMaps = target_gis.content.clone_items([template_WebMap], copy_data=False)
# get contents and update urls
result_WebMap = getResultWebMap(result_WebMaps)
webMap_content = result_WebMap.get_data()
updated_WebMap_content = updateWebMapContent(webMap_content, new_hosted_service_url)
# prepare call to upload rest endpoint
update_url = "{}/sharing/rest/content/users/{}/items/{}/update".format(
portalUrl, target_gis.users.me.orgId, result_WebMap.id)
update_params = {
'text': json.dumps(updated_WebMap_content),
'token': token,
'f': 'json'
}
update_response = urlopen(update_url, bytes(urlencode(update_params), 'utf-8'))
update_ouput = json.loads(update_response.read().decode("utf-8"))
# update_output = {'error': {'code': 400, 'message': 'Item does not exist or is inaccessible.',
# 'messageCode': 'CONT_0001', 'details': []}}
So I am currently unable to update the map's contents in any way. Is there a preferred workflow for making updates to the Urls in the layers of a WebMap using the Python API?
Thanks in advance,
Daniel