Why can't I save a JSON locally with the arcgis python api

1058
2
06-02-2017 02:03 AM
ANSAdviesgroep
New Contributor II

Really strange behaviour. When I create a replica of a file and set as data-format 'filegdb':

replica1 = flc.replicas.create(replica_name = "test", layers='0', data_format='filegdb', out_path='/Users/username/Desktop')
print(replica1)

I get:

/Users/...username.../Desktop/b60ff113bc944907bd37ce33ced3f22b.zip

and file appears on Desktop.
However, when I change data_format to 'json' or when I delete the line (since JSON is default) the result is:

{'transportType': 'esriTransportTypeUrl', 'URL': 'http://services7.arcgis.com/...code.../ArcGIS/rest/services/...name.../FeatureServer/replicafiles/a21d42fdfbd440e698d4646f48442e4a.json'}

And no file appears on Desktop. What can go wrong here? I use the default and follow: Checking out data from feature layers using replicas | ArcGIS for Developers 

Extract and Sync are on, I check that beforehand.

0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

What you are seeing is expected behavior.  In the documentation you reference, there is a link to Create Replica for the ArcGIS REST API.  Since the ArcGIS API for Python is really driven by the ArcGIS REST API, it is important to understand the REST API equivalent of Python API functions.  In this case, the ArcGIS REST API only supports json and sqlite data formats while the Python API supports more, so the Python API is doing something with the results from json to create file geodatabase or shape files.  You are getting the URL of the JSON results returned to you, you just need to download it to a file if you want to store it in a file.

0 Kudos
ANSAdviesgroep
New Contributor II

You do know that the sqlite is exporting to the out_path. 

So REST API: json | sqlite

Python API: json | sqlite | filegdb | shapefile

And in the python API the possibility to select an out_path. 

Result: Only json doesn't export to the mentioned out_path while the other's do. 

So, don't you agree that it seems is off? Or are you able to get the json on out_path location?

0 Kudos