When adding a new item, can you include item json?

962
2
Jump to solution
01-18-2018 02:59 PM
CourtneyClaessens
Occasional Contributor III

I'm trying to add a new item to ArcGIS Online with predetermined item json. I thought I could do this by referring to my json file in the `data` value, so something like :

gis.content.add(item_properties, data='/Users/cour7816/data.json')‍‍‍

That's not working for me. I've also tried using another item's URL for data - no dice.

Is there another way to achieve this?

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Courtney, you need to send the json as a kvp in the item_properties dictionary. You can read the json and pass it as a string (use json.dumps()). See below for an example.

import json
json_file = json.loads('your_json.json')
item_properties = {'title':'Web scene with photo realistic buildings',
                            'type':'Web Scene',
                            'snippet':'This scene highlights buildings of Montreal, Canada',
                            'tags':'ArcGIS Python API',
                            'text': json.dumps(json_file)}

web_scene_item = gis.content.add(item_properties)

View solution in original post

2 Replies
by Anonymous User
Not applicable

Courtney, you need to send the json as a kvp in the item_properties dictionary. You can read the json and pass it as a string (use json.dumps()). See below for an example.

import json
json_file = json.loads('your_json.json')
item_properties = {'title':'Web scene with photo realistic buildings',
                            'type':'Web Scene',
                            'snippet':'This scene highlights buildings of Montreal, Canada',
                            'tags':'ArcGIS Python API',
                            'text': json.dumps(json_file)}

web_scene_item = gis.content.add(item_properties)
CourtneyClaessens
Occasional Contributor III

Perfect! Thank you for your help!

0 Kudos