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<SPAN class="punctuation token">.</SPAN>SignInToPortal_server<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"AGOL_USER"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"AGOL_PASS"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com%2F" target="_blank">http://www.arcgis.com/</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>UploadServiceDefinition_server<SPAN class="punctuation token">(</SPAN>sd<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"My Hosted Services"</SPAN><SPAN class="punctuation token">,</SPAN> service<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2FXXXX.maps.arcgis.com" target="_blank">https://xyz.maps.arcgis.com</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"AGOL_USER"</SPAN><SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">)</SPAN>
item <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content<SPAN class="punctuation token">.</SPAN>add<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"xyz.sd"</SPAN><SPAN class="punctuation token">)</SPAN>
published_item <SPAN class="operator token">=</SPAN> item<SPAN class="punctuation token">.</SPAN>publish<SPAN class="punctuation token">(</SPAN>overwrite<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>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?