AnsweredAssumed Answered

Upload mxd to AGOL with Python

Question asked by MikelSant on Sep 24, 2018
Latest reply on Jan 31, 2019 by cbroome


I need to create a Python script to upload an MXD to AGOL. I have created an script in arcpy to create a service definition file (*.sd) from the mxd. I have not been able to upload the sd to AGOL unless ArcMap is open. I use the following code:

arcpy.SignInToPortal_server("AGOL_USER", "AGOL_PASS", "")
arcpy.UploadServiceDefinition_server(sd, "My Hosted Services", service)

I get the following error:

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Server: Dataset My Hosted Services does not exist or is not suppoted
Failed to execute (UploadServiceDefinition).


I have been able to upload the service document file using ArcGIS API for Python:

gis = GIS("", "AGOL_USER", password)
item = gis.content.add({}, "")
published_item = item.publish(overwrite=True)


a) How can I upload the service definition file to AGOL using arcpy? The script needs to be run scheduled, so I cannot have ArcMap open 

b) Would be posible to merge arcpy code with ArcGIS API for Python?