def updateItemUrl(self, itemId, oldUrl, newUrl, folderID=None):
        try:
            params = urllib.urlencode({'token' : self.user.token,
                                       'f' : 'json'})
            print 'Getting Info for: ' + itemId
            # Get the item data
            reqUrl = self.user.portalUrl + '/sharing/rest/content/items/' + itemId + '?' + params
            itemReq = urllib.urlopen(reqUrl).read()
            itemString = str(itemReq)
            itemInfo = json.loads(itemString)

            if not itemInfo.has_key('url'):
                print itemInfo['title'] + ' doesn\'t have a url property'
                return
            print 'Updating ' + itemInfo['title']
            existingURL = itemInfo['url']

            # Double check that the existing URL matches the provided URL
            if itemString.find(oldUrl) > -1:
                # Get the item folder.
                if itemInfo['ownerFolder']:
                    folderID = itemInfo['ownerFolder']
                else:
                    folderID = ''
                # Update the item URL
                updatedURL = existingURL.replace(oldUrl, newUrl)
                updateParams = urllib.urlencode({'url' : updatedURL})
                updateUrl = self.user.portalUrl + '/sharing/rest/content/users/' + self.user.username + '/' + folderID + '/items/' + itemId + '/update?' + params
                updateReq = urllib.urlopen(updateUrl, updateParams).read()
                modResponse = json.loads(updateReq)
                if modResponse.has_key('success'):
                    print "Successfully updated the url."
                else:
                    raise AGOPostError(itemId, modResponse['error']['message'])
            else:
                print 'Didn\'t find the specified old URL: ' + oldUrl
        except ValueError as e:
            print e
        except AGOPostError as e:
            print 'Error updating item: ' + e.msg
Use this to update the URL for items such as Map Services.
dataset/ETHPy150Open Esri/ago-tools/agoTools/utilities.py/Utilities.updateItemUrl