Select to view content in your preferred language

ArcGIS Online and Arcpy

378
12
3 weeks ago
CodyPatterson
Regular Contributor

Hey all,

I was recently given the project to put together a tool that syncs our AGOL environment to our local database and vice versa. This was already created a few years back by another employee but it recent started failing. I found that it was using arcpy.ListFields(SourceLayer) and it now shows that {AGOL_URL} does not exist or is not supported.

I attempted many ideas to get this to continue working with ArcPy, but I've been stuck for a few hours now, and have decided to look back into ArcGIS API for Python to get this completed.

My idea was to bring down the FGDB into a local file, and then use that with ArcPy, but the FGDB is 100+ GB and I cannot do this often. How should I approach this?

Any help is appreciated, thank you!

Cody

0 Kudos
12 Replies
CodyPatterson
Regular Contributor

Code Snippet:

feature_layer_url = "https://services9.arcgis.com/{identifier}/arcgis/rest/services/{Layer}/FeatureServer/{LayerNum}?token={token}"

for f in arcpy.ListFields(feature_layer_url):
    print(f)
0 Kudos
JakeSkinner
Esri Esteemed Contributor

@CodyPatterson,

Is there a unique field and edit tracking enabled?  I would recommend creating a script that:

  • queries the features that were edited in the last day using the last_edited_date field and download those features using Export Features
  • create a list of downloaded features using the unique field
  • delete these features from the local database
  • append the downloaded features to the local database

Be sure your script uses arcpy.SignIntoPortal and you can access the URL of the service without generating a token.

0 Kudos
CodyPatterson
Regular Contributor

Hey @JakeSkinner 

Thank you for the suggestions, unfortunately the issue persists with the Export Features, it still states that it does not exist or is not supported. This is equipped with a unique field along with edit tracking so I'm not entirely sure what the main issue is.

Since this project is somewhat urgent, I ended up just redesigning all the ArcPy functions that were present into ArcGIS API for Python functions, and made this using custom query methods.

If you have any further suggestions I will surely try them, as I enjoy using ArcPy much more than ArcGIS API for Python.

Cody

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@CodyPatterson did you include arcpy.SignIntoPortal?  Ex:

 

 

arcpy.SignIntoPortal('https://www.arcgis.com', 'agolAdmin', 'gis12345')

feature_layer_url = "https://services9.arcgis.com/{identifier}/arcgis/rest/services/{Layer}/FeatureServer/{LayerNum}"

for f in arcpy.ListFields(feature_layer_url):
    print(f)

 

 

0 Kudos
CodyPatterson
Regular Contributor

Hey @JakeSkinner 

That was present and I confirmed that the credentials were working for login, that unfortunately did not change the outcome.

Cody

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Can you share the feature service to an AGOL group and invite my user account (jskinner_rats)?  I can take a look.

0 Kudos
CodyPatterson
Regular Contributor

Hey @JakeSkinner 

The feature layer I'm working with is proprietary and cannot be shared out to the public unfortunately, I've created a separate feature layer, which experiences the same issue.

Here's what I see:

CodyPatterson_1-1719866603642.png

Cody

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@CodyPatterson try specifying the index number in the Feature Service URL (i.e. /FeatureServer/0).

0 Kudos
CodyPatterson
Regular Contributor

Hey @JakeSkinner 

I came up with the same error, did yours end up going through?

CodyPatterson_0-1719947194154.png

Cody

0 Kudos