Select to view content in your preferred language

Download ArcGIS Online item´s data to json file

2192
2
Jump to solution
10-31-2022 08:06 AM
JessicaPettersson
Emerging Contributor

Hello,

I want to download item´s data resource from ArcGIS Online (that you can se in ArcGIS Online Assistant) for the following types:

Web Map, Web Mapping Application, Storymap, Dashboard, QuickCapture, Workforce Project, Map Service and Feature Service.

I have started with Web Map and this is my code:

JessicaPettersson_0-1667228244827.png

 

If I run this in ArcGIS Pro python window and print "item" I get the right information (I can se operational Layers and so on), but if I run this in IDLE I get the item properties.

Could anyone suggest how to fix this and explain why I get different results, please.

0 Kudos
1 Solution

Accepted Solutions
Brian_Wilson
Honored Contributor

I am not sure about your results running in Pro but you need to change a couple lines in your script.

If you read the data with item.get_data(False) into a variable (like "mydata") it will be in one big text string so you can just write it out. In your script you write "item" instead, which means you should be seeing only the metadata like what you see in the details page like "owner" and "tags" etc.

(In line 3 for my convenience testing I changed the file_path to write in to the local folder instead of /temp/* and I replace spaces with _ because I hate spaces in filenames, they always hurt me eventually.)

 

for item in items:
    mydata = item.get_data(False)
    file_path = str(item['title'] + '.' + item['type'] + '.json').replace(" ", "_")
    with open(file_path, "w") as outfile:
        fp.write(mydata)

 

 

View solution in original post

0 Kudos
2 Replies
Brian_Wilson
Honored Contributor

I am not sure about your results running in Pro but you need to change a couple lines in your script.

If you read the data with item.get_data(False) into a variable (like "mydata") it will be in one big text string so you can just write it out. In your script you write "item" instead, which means you should be seeing only the metadata like what you see in the details page like "owner" and "tags" etc.

(In line 3 for my convenience testing I changed the file_path to write in to the local folder instead of /temp/* and I replace spaces with _ because I hate spaces in filenames, they always hurt me eventually.)

 

for item in items:
    mydata = item.get_data(False)
    file_path = str(item['title'] + '.' + item['type'] + '.json').replace(" ", "_")
    with open(file_path, "w") as outfile:
        fp.write(mydata)

 

 

0 Kudos
JessicaPettersson
Emerging Contributor

Thanks! That solved my problem. And fixing spaces in the filename was a bonus.

I changed fp.write to outfile.write to get i working ok.

0 Kudos