Upload mxd to AGOL with Python

805
1
09-24-2018 09:05 AM
MikelSantamaria
New Contributor

Hi

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", "http://www.arcgis.com/")
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("https://XXXX.maps.arcgis.com", "AGOL_USER", password)
item = gis.content.add({}, "XXX.sd")
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?

1 Reply
CJ_Broome
New Contributor III

I would also like to implement this through arcpy