Can the Python API be used in a Web Tool for managing Portal Items?

03-24-2020 10:04 AM
Occasional Contributor III


I've created a Script Tool in ArcPro 2.5 that uses the Python API to manage hosted layers.  It is not passing the Analyze step in the Web Tool publishing workflow to publish to Portal 10.8.  The line where the GIS is being declared is causing a broken project data source error.  This is a real bummer.  I think I have to scrap this entire model.  It is simple, but very critical for copying an empty hosted layer in Portal to a new service for a user to edit in a web app.

Any thoughts on whether the Python API can be used in a GP Service?  My alternatives are a custom server side app or the javascript api and do it all in the widget.  This solution of the python API would be perfect.

5 Replies
Occasional Contributor III

I've decided to go with a server side python web deployment.  I am wondering if there is a way to register the portal somehow for this to work in a web tool.  I've not found any documentation stating either way.  I was thinking the federation would be registering a connection, but perhaps its just not supported to begin with?

0 Kudos
New Contributor II

Have you succeeded with publishing your workflow to portal? Can you describe your workaround? I have run into the same issue lately. 

0 Kudos
Occasional Contributor III

Using a restAPI python server app, makes a request to a url and runs python api code to create a new service and layer from an empty hosted feature layer in Portal, then passes the url of the new layer back to the client so it can be edited. 

To create the new hosted feature layer from an existing empty hosted feature layer I am using 

target_item = template_layer.copy_feature_layer_collection(layout_name,
 description="New Layer Created From Template",

I've not attempted this as a GP Service / WebTool again recently though to see if this data type is supported.  It is something I will be testing again soon though.

New Contributor III

I've recently found that the Web Tools published from ArcPro 2.7.1 do allow the GIS object to be created.  This might work with previous versions as well.

The trick is that the Portal URL has to be provided as a user parameter to the script tool.  Otherwise, the Analyze step fails with a broken Project Data Source if the Portal URL is hardcoded.

This is a game changer.

Occasional Contributor III

Merely importing arcgis causes publish to fail for me. Not even creating the gis object. Passes Analyze, but fails on publish.

0 Kudos