I am trying to create a web tool from a .pyt that will add a new feature to a feature class based on xy values. I have the working fine with local data in Arc Pro, but it does not work when it is shared as a web tool. I believe that I narrowed it down to the arcpy.da.InsertCursor not accepting the REST page of my hosted feature layer as a parameter. I want this tool to eventually end up in a geoprocessing widget in Web App Builder app.
Is there a way around the cursor not working?
Thanks,
param0 = parameters[0].valueAsText #Feature class to gain entry
param1 = parameters[1].valueAsText #x
param2 = parameters[2].valueAsText #y
#Message showing params values
arcpy.AddMessage('param0 = ' + param0 + '\n' + 'param1 = ' + param1 + '\n' + 'param2 = ' + param2)
#Define the coodrdinates from parameters
coord_string = f'{param2} {param1}'
#creating a point
point_geometry = arcpy.FromCoordString(coord_string, 'DD')
#Add a messege with details about point
spatref = point_geometry.spatialReference.factoryCode
coord = point_geometry[0]
arcpy.AddMessage(f'spatial reference = {spatref} \n coodinates = {coord}')
# Create an insert cursor for a table specifying the fields that will have values provided
fields = ['SHAPE@','SHAPE@']
cursor = arcpy.da.InsertCursor(param0, fields)
# Create new rows
cursor.insertRow([point_geometry, point_geometry])
# Delete cursor object
del cursor
InsertCursors do not work with REST endpoints because it is an entirely different ecosystem. The REST endpoint is essentially server side code, which takes requests through http (GET, POST, PUT, DELETE, PATCH, etc.) and returns information. To do anything with the underlying data, you need to format your request to the REST endpoint accordingly.
I think you may have two options here. You can use the ArcGIS for Python API methods to insert the points on the hosted Featurclass, or if you are stuck having to use the REST endpoint, there are some things that you need to set up to allow POST edits to that featureserver. Finally, in your web tool, you'll need to replace the Insert cursor with which ever method you chose to pursue.
Thank you for the help. That makes a lot of sense. I think that I was getting hung up on the ESRI web tool documentation that says any script should work.
That's how they get ya! That first part of that sentence, (and more importantly, the first word (Most...) is the kicker. They should probably rephrase that whole statement.
If you need any help with either of those options, there are some smart folks on here.