Python API: Have AGOL file GDB item object. How construct proper in_data parameter for ExportXMLworkspaceDocument?

610
3
Jump to solution
04-18-2023 03:35 PM
Labels (1)
ThomasCrossman
New Contributor III

I would like to use the ExportXMLWorkspaceDocument geoprocessing tool (in arcpy) to generate an XML document (schema only) from an API for Python item object of a file geodatabase (FGDB) that currently resides in the Content/My Content area of my company's AGOL portal.  The FGDB is an export of a hosted feature service (hosted feature layer collection, to be precise) generated with code like:

 

 

result = item_object.export(feature_layer_name, 'File Geodatabase')
itemID = result.id

 

 

During the run, I have item_object (the feature service Item) and result (the FGDB Item).  I would export the XML document with the geoporcessing tool thus:

 

 

arcpy.management.ExportXMLWorkspaceDocument(in_data, out_file, 'SCHEMA_ONLY')

 

 

I am in many ways an AGOL and REST novice (though the Python API does make a lot of sense), and I find the various types of URL formats and what they point to quite confusing.  So, I suppose I have two questions, really:

  1.  What value would I use for arcpy.env.workspace?  (Maybe I don't need to set this if I am using fully qualified URLs all around?)
  2. What value would I use for the in_data parameter of the tool call to refer properly to the FGDB in My Content?

I assume that these values are going to be various combinations of URLs and item IDs, but I am really confused now and have had no luck getting this to work.  (I did see that there is an item_card property for an Item object, but even if that would do the same thing as the geoprocesing tool (which I doubt), there seems to be no parameter for restricting to schema only output.)  Any help with this stuff would be greatly appreciated.  As I have 28 feature services to do this for, I would really like to get the automation working.

0 Kudos
1 Solution

Accepted Solutions
Kepa
by Esri Contributor
Esri Contributor

Hello @ThomasCrossman,

You are dealing here with an item object so I don't think you can pass the url, item, or any other endpoint to the in_data parameter.

Answering your questions:

1) No need of setting arcpy.env.workspace at all

2) in_data accepts Feature Class; Feature Dataset; Raster Dataset; Table; Workspace. In your case, you will have to download the item (filegdb) locally, extract it (cause it is compressed) and pass the extracted GDB path into the in_data parameter.

After executing ExportXMLWorkspaceDocument function you always can upload that XML to your content throught the API (ContentManager.add() method)

Hope that helps, cheers!

View solution in original post

0 Kudos
3 Replies
Kepa
by Esri Contributor
Esri Contributor

Hello @ThomasCrossman,

You are dealing here with an item object so I don't think you can pass the url, item, or any other endpoint to the in_data parameter.

Answering your questions:

1) No need of setting arcpy.env.workspace at all

2) in_data accepts Feature Class; Feature Dataset; Raster Dataset; Table; Workspace. In your case, you will have to download the item (filegdb) locally, extract it (cause it is compressed) and pass the extracted GDB path into the in_data parameter.

After executing ExportXMLWorkspaceDocument function you always can upload that XML to your content throught the API (ContentManager.add() method)

Hope that helps, cheers!

0 Kudos
ThomasCrossman
New Contributor III

Hello, @Kepa 

Yes, indeed.  That does answer my question--an unfortunate answer but just what I needed to know.  I was trying to avoid the download/uzip part, as each of the 28 FGDBs (exported feature services) would be 2 to 10GB in size.  I simply don't have the time or the local disk space to do the download/unzip.  I suspect that a FGDB exported to My Content from a feature service on ArcGIS Online is some kind of compressed archive that isn't directly readable.  So, perhaps I will submit an Idea that arcpy implementations of geoprocessing tools that operate on workspaces (like ExportXMLWorkspaceDocument) be capable of consuming URLs of exported FGDBs on ArcGIS Online as workspaces for input_data.  That would certainly up the game!  Thanks for the help, @Kepa.  

0 Kudos
RhettZufelt
MVP Frequent Contributor

In Desktop, I often just select one feature, then export to new featureclass to maintain all the schema info, then delete the one feature to have new dataset with matching schema.

Not sure if this would work for you, but could you use the API to make a copy of the feature services, truncate the data, then export to FGDB (which is now pretty much just the schema) which could then be copied locally, and exported to xml.

R_