Python Script to Download Data from Hosted Feature Layer in Enterprise Portal

124
3
08-12-2022 08:55 AM
JoshSmithWCWD
New Contributor

Hi!

I have a model that I run in ArcGIS Pro that uses the table to table tool to export the data from a hosted feature layer to a csv. We'd like to get this process automated with a python script. Does anyone have one that they would be willing to share that does this or something similar? 

Everything example I've found online uses ArcGIS Online and not Enterprise.

Thanks!

0 Kudos
3 Replies
JeffK
by MVP Regular Contributor
MVP Regular Contributor

You can export your model to a script, which will give you the best 'working' script example using your variables.

exporting-a-model-to-python 

0 Kudos
JoshSmithWCWD
New Contributor

Hey Jeff,

Thanks for the reply. That is what we've tried, but have been unsuccessful so far. We get the following error: ERROR 000732: Input Rows: Dataset ### does not exist or is not supported

It seems like the dataset is inaccessible in our Enterprise Portal where we use an active directory. Would you happen to have a sample script on accessing an enterprise environment?

Thanks again!

0 Kudos
JeffK
by MVP Regular Contributor
MVP Regular Contributor

cool, well...  connecting to a portal can be done a few ways. with a local account:

from arcgis.gis import GIS
portalGIS = GIS("https://your portal", 'username', "password")

dataitem = portalGIS.content.get('the id of the table that you want to get')

Using oauth takes some steps to get set up, provided here which involves creating an Application to set up an client id.

client_id = 'you have to creat it to get it'
portalGIS = GIS(client_id=client_id, url='your portal stuff')

dataitem = portalGIS.content.get('the id of the table that you want to get')

 ... this will prompt the user to connect though, and required a generated key to be pasted last time I ran it.  If you want it hands free automated, setting up the local portal account would work easiest.

 

Is the data shared at a level where you can get it?

0 Kudos