AnsweredAssumed Answered

How to modify web map URL of a published web mapping app

Question asked by williamskg6 on Sep 5, 2018
Latest reply on Sep 12, 2018 by williamskg6

I have a bunch of web mapping applications that have been copied from one portal into another.  In the process, the URL for the Web Map that backs the web mapping application is simply copied from the source portal.  I need to be able to modify the URL of the Web Map in the destination portal's Web Mapping Application.  I have searched high and low and cannot find out how one would accomplish this.  ArcGIS Online Assistant doesn't do it, and I would prefer to do it via Python anyway, whether through the ArcGIS API for Python or via the REST API.  

 

I thought I was making progress by getting the item's data from the source ( the_item.get_data() from the API for Python), editing it, and then publishing it.  I am using some code from Esri found on the 'net, with a function that adds the item, but it also needed the item's description which is obtained via the REST API at the ../sharing/rest/content/items/itemID endpoint of the source Web Mapping App.  I then edit that description dictionary and add the item to the destination portal via the code from Esri, but I can't figure out how to set the new Web Mapping App's web map URL without ruining the URL for the Web Mapping App itself.  It ends up using the same URL for both the Web Map AND the Web Mapping Application, which means if you click "View Application" on the new Web Mapping Application it actually takes you to the Web Map's URL instead of opening the Web Mapping Application.

 

Here's the function I use to get the source item's description:

def addItem(username, folder, description, data, portalUrl, token, thumbnailUrl=''):
    '''Creates a new item in a user's content.'''
    description = json.dumps(description).replace('None', '')
    parameters = urllib.parse.urlencode({'item': json.loads(description)['title'],'text': data, 'overwrite': 'true', 'thumbnailurl': thumbnailUrl, 'token' : token, 'f' : 'json'})
    postParameters = urllib.parse.urlencode(json.loads(description)) + '&' + parameters
    postParameters = postParameters.encode("utf-8")
    the_request = urllib.request.urlopen(portalUrl + '/sharing/rest/content/users/' + username + '/' + folder + '/addItem?', postParameters)
    response = the_request.read()
    return response

 

Since documentation is not exactly user friendly and examples are nonexistent I'm not sure I was even on the right track.  Maybe there's a far easier way to do this.  I'm all ears!

Outcomes