How to publish a feature service to ArcGIS Online from an mxd USING PYTHON?

24972
45
Jump to solution
03-25-2013 07:06 PM
BenoitMetzger
New Contributor II
Hi All,

I would like to automate publishing feature services - from an mxd using Python to my AG Online account.

I did this successfully manually using the menu: Share as -> Service, Publish a service - Feature Access Capabilities etc...

Using Python, I managed to publish the service definition file on AG Online using:
arcpy.mapping.CreateMapSDDraft()
arcpy.mapping.AnalyzeForSD()
arcpy.StageService_server()
arcpy.UploadServiceDefinition_server()

But I could not find a way to publish a feature service to AG Online! I must be missing something. Any help would be really appreciated.

Thanks in advance!
Tags (2)
45 Replies
KevinHibma
Esri Regular Contributor
Kaushal Shah:
Right, the code is to modify the XML, thus it must go before stage.
As long as the service name doesn't change, the link should remain the same. The hosted service account id is a set of letters and numbers which to the best of my knowledge doesnt change. So to the best of my knowledge, it should be ok.

tribeiro:
You've made a GP Service to perform this publishing routine?
I'd strongly recommend against that. The Upload and Stage tools (which are required in this workflow) are not designed to be re-published in your own geoprocessing service. I'd suggest making it a scheduled task on one of your desktop machines.
0 Kudos
TiagoRibeiro
Occasional Contributor

tribeiro:
You've made a GP Service to perform this publishing routine?
I'd strongly recommend against that. The Upload and Stage tools (which are required in this workflow) are not designed to be re-published in your own geoprocessing service. I'd suggest making it a scheduled task on one of your desktop machines.

Thanks for the reply Kevin, that's what I thought, and the scheduled task approach was (and now will be) my next step.
Any plans of making those tools, Upload and Stage, available through geoprocessing services in the future?
0 Kudos
KevinHibma
Esri Regular Contributor
Not in 10.2, and no plans to the best of my knowledge after that.
What these tools do, and how they work is not conducive to being used in a service. I'd say at best they would act like a scheduled task that could be modified slightly at execution time.
I say this as the server will most likely have to have the MXD + Data you want to publish. It would be a pretty involved service to that gets both the MXD and all required data from the client, extracts it somehow, and then publishes. So I'm making the assumption your server already has the data/mxds on it. If thats the case, setting it up as a scheduled task would probably be more straight forward.
I'm not saying these as a service cant be done - I'm just saying its something that we haven't tested and I could imagine a few areas which will be difficult to overcome. As such, I'd take the "easier" approach of just making a scheduled task.
0 Kudos
KevinHibma
Esri Regular Contributor
Just for anyone else who comes upon this thread...
Jeff and I posted a blog with the python script to:
-CreateMapSDDraft, Analyze, Stage and Upload for map documents to be pushed to ArcGIS.com as a hosted feature service /w overwrite and shared to arcgis.com turned on.

http://blogs.esri.com/esri/arcgis/2013/04/23/updating-arcgis-com-hosted-feature-services-with-python...
0 Kudos
JamesCrandall
MVP Frequent Contributor

I'm attempting to implement the 10.2 version of this script and keep running into the error that Consolidating the data failed when attempting to stage the service from a SDDraft document.

Traceback (most recent call last):

  File "C:\Python27\ArcGISx6410.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript

    exec codeObject in __main__.__dict__

  File "\\AGOL\py\update.py", line 406, in <module>

    updateSD()

  File "\\AGOL\py\update.py", line 249, in updateSD

    arcpy.StageService_server(newSDdraft, SD)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\server.py", line 1204, in StageService

    raise e

ExecuteError: ERROR 001270: Consolidating the data failed.

Failed to execute (StageService).

Any ideas?

deleted-user--MMnVrog9xw_
Occasional Contributor

I know this is an old post, but that link seems to be dead. Is the blog post archived somewhere? 

0 Kudos
ErikEndrulat
Occasional Contributor
I've attempted to use this sample and am able to successfully update feature services with 10.1, but not with 10.2. I'm encountering the following error:
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Server: Dataset My Hosted Services does not exist or is not supported
WARNING 001404: You are not signed in to ArcGIS Online.
Failed to execute (UploadServiceDefinition).

[ATTACH=CONFIG]27306[/ATTACH]

This appears to be an issue with the arcpy SignInToPortal function. I'm able to publish/overwrite the service with 10.2 only when I comment out the SignInToPortal line and sign in separately using ArcGIS Desktop. Is anyone else having this problem with ArcGIS 10.2? Are there any workarounds?

Thanks,
Erik
0 Kudos
DanikBourdeau2
New Contributor III
I'm able to publish/overwrite the service with 10.2 only when I comment out the SignInToPortal line and sign in separately using ArcGIS Desktop. Is anyone else having this problem with ArcGIS 10.2? Are there any workarounds?

Thanks,
Erik


Since 10.2, this is how I have had to publish/overwrite services as well.  Not that big of a deal but I do wish that somewhere it would have been stated that SignInToPortal doesn't work like it used to.
0 Kudos
KevinHibma
Esri Regular Contributor
Danik, Erik,

With the 10.2 release, the authentication method for Portal has changed, as such the SignIntoPortal tool is no longer necessary.

We're currently investigating why the tool is causing these sorts of issues. (It should have just passed through the tool with a warning message indicating you need to Sign In from the ArcMap menu)

To get around the issue for now:

  • Dont use the SignIn tool in your script/workflows

  • Any machine you want to run this script from, must first open ArcMap, and use File > Sign In with the automatic option checked

0 Kudos
ErikEndrulat
Occasional Contributor
Kevin,

Great, thanks for weighing in on the changes in 10.2 regarding the SignIn function.

Do you have a recommended workflow to update feature services using a scheduled task when a user isn't logged into the machine. Is that no longer possible?

Thanks much,
Erik
0 Kudos