AnsweredAssumed Answered

Publishing ArcGIS API python script as a geoprocessing tool

Question asked by bljackson on Jul 27, 2017
Latest reply on Sep 12, 2017 by paul.haakma

I'm trying to publish a geoprocessing tool from Pro using a python script and the ArcGIS API for Python.  The script is very simple and works well from Pro, but it will not publish to either of my Server sites, one which is hosted.  Is it not possible to publish using this new API to Server?  Can it only be used from the local workstation python interface and/or Pro?

 

Here is my script:

from arcgis.gis import GIS
import shutil, os, arcpy

newPolyName = arcpy.GetParameterAsText(0)          # Layer name
featureType = arcpy.GetParameterAsText(1)          # Feature type:  Point, Line or Polygon
userName = arcpy.GetParameterAsText(2)             # User login
pword = arcpy.GetParameterAsText(3)                # User password

gis = GIS(r"https://gis.cdatribe-nsn.gov/arcgisportal", userName, pword)

newShapeFileName = r"\\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile" + chr(92) + newPolyName + ".shp"
print(r'copy \\gis-bj\E\Data\AutoPublishUTMLayer\Empty' + featureType + r'UTM.* \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile' + chr(92) + newPolyName + '.*')
os.system(r'copy \\gis-bj\E\Data\AutoPublishUTMLayer\Empty' + featureType + r'UTM.* \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile' + chr(92) + newPolyName + '.*')
shutil.make_archive(r"\\gis-bj\E\Data\AutoPublishUTMLayer" + chr(92) + newPolyName, 'zip', r"\\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile")

data = r"\\gis-bj\E\Data\AutoPublishUTMLayer" + chr(92) + newPolyName  + ".zip"
print(data)
shpfile = gis.content.add({}, data)
published_service = shpfile.publish({"name": newPolyName,"targetSR":{"wkid":26911}})

os.system(r'del /q \\gis-bj\E\Data\AutoPublishUTMLayer\OutputShapefile\*.*')
os.system(r'del /q \\gis-bj\E\Data\AutoPublishUTMLayer\*.zip')

Outcomes