I am using ArcREST python package, specifically the add_item.py example to upload a shapefile to ArcGIS Online (AGOL).

The example is straightforward and I have successfully uploaded a shapefile to my org account.

However I want to be able to upload it as a hosted layer so that I can immediately pull the ArcGIS REST Services URL that is created when you would otherwise normally add an item on AGOL and check the box "Publish this file as hosted layer".

Perhaps there is an item parameter I am missing or something of that sort.

usernameInput = raw_input("Please enter your username: ")
passwordInput = raw_input("Please enter your password: ")

securityinfo = {}
securityinfo['security_type'] = 'Portal'#LDAP, NTLM, OAuth, Portal, PKI
securityinfo['username'] = usernameInput
securityinfo['password'] = passwordInput
securityinfo['org_url'] = "http://www.arcgis.com"
securityinfo['proxy_url'] = proxy_url
securityinfo['proxy_port'] = proxy_port
securityinfo['referer_url'] = None
securityinfo['token_url'] = None
securityinfo['certificatefile'] = None
securityinfo['keyfile'] = None
securityinfo['client_id'] = None
securityinfo['secret_id'] = None

root = Tkinter.Tk()

filename = tkFileDialog.askopenfilename(parent=root,title='Select File to Upload')

upload_file = filename

    shh = securityhandlerhelper.securityhandlerhelper(securityinfo)
    if shh.valid == False:
        print shh.message
        admin = arcrest.manageorg.Administration(securityHandler=shh.securityhandler)
        content = admin.content
        userInfo = content.users.user()

        titleInput = raw_input("Please enter a title for your upload: ")

        itemParams = arcrest.manageorg.ItemParameter()
        itemParams.title = titleInput
        #itemParams.thumbnail = None
        Valid types
        "Shapefile", "CityEngine Web Scene", "Web Scene", "KML",
                     "Code Sample",
                     "Code Attachment", "Operations Dashboard Add In",
                     "CSV", "CSV Collection", "CAD Drawing", "Service Definition",
                     "Microsoft Word", "Microsoft Powerpoint",
                     "Microsoft Excel", "PDF", "Image",
                     "Visio Document", "iWork Keynote", "iWork Pages",
                     "iWork Numbers", "Map Document", "Map Package",
                     "Basemap Package", "Tile Package", "Project Package",
                     "Task File", "ArcPad Package", "Explorer Map",
                     "Globe Document", "Scene Document", "Published Map",
                     "Map Template", "Windows Mobile Package", "Pro Map",
                     "Layout", "Layer", "Layer Package", "File Geodatabase",
                     "Explorer Layer", "Geoprocessing Package", "Geoprocessing Sample",
                     "Locator Package", "Rule Package", "Workflow Manager Package",
                     "Desktop Application", "Desktop Application Template",
                     "Code Sample", "Desktop Add In", "Explorer Add In",
                     "ArcGIS Desktop Add-In", "ArcGIS Explorer Add-In",
                     "ArcGIS Explorer application configuration", "ArcGIS Explorer document"
        itemParams.type = "Shapefile"
        itemParams.overwrite = True
        itemParams.description = "Auto Upload File"
        itemParams.tags = "tags"
        itemParams.snippet = "Auto Upload File"
        itemParams.typeKeywords = "Data"
        #itemParams.filename = upload_file
        item = userInfo.addItem(
            filePath= upload_file,
        print item.title + " created"

    line, filename, synerror = trace()
    print "error on line: %s" % line
    print "error in file name: %s" % filename
    print "with error message: %s" % synerror
  • Welcome to GIS SE! As a new user please take the Tour. Are you able to include a code snippet that illustrates what you have tried and where you are stuck? – PolyGeo Mar 7 '16 at 5:37
  • The code snippet I added is what I edited from the add_item.py file (hyperlink found in question). I am curious if there is a parameter or something I can add to make it upload as a hosted layer. Thanks! – jasonrberney Mar 8 '16 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.