Select to view content in your preferred language

Updating multiple feature services on AGOL using Python

2333
1
Jump to solution
08-02-2016 01:37 PM
MelanieWawryk
Frequent Contributor

I have a python script that was adapted from update-hosted-feature-service/update.py at master · arcpy/update-hosted-feature-service · GitHub  that uses an oracle table instead of the ini file to loop through AGOL updates. The table has the AGOL name, the mxd name, tags etc.that is updates but. It works fine when there are no spaces on the AGOL side but fails in the def publish(self) section on line 230  when there are spaces in AGOL.   So for example if I have Bike Racks as BikeRacks on AGOL, it will run. I am pretty sure it is a simple error but I can seem to see it.    

Line 230: return jsonResponse['services'][0]['serviceItemId']

---------------------------

Error

---------------------------

KeyError: 'services'

---------------------------

OK  

---------------------------

Oracle table:

AGOL:

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MelanieWawryk
Frequent Contributor

Thank you to  Jing Yan from Esri Canada for figuring this one out. 

Here is the solution:

In  ArcGIS Online, the title of an item is stored in an “title” parameter (e.g. “Nicer Name”), while the original service name/SD file name is stored in a “name” parameter (e.g. “SqueezedName.sd”). 

The high-level steps are: 
1)    Use service name, e.g. “Nicer Name”, to fetch the same titled item, and then get item ID to decide which item and its SD to update. 
2)    Fetch the original service name/SD file name, e.g. “SqueezedName”, through the item name parameter, and use “SqueezedName” to create new SD and overwrite the original service. 
3)    Now the item title “Nicer Name” will be reverted back to its original service name “SqueezedName”. So the last step is to use Update Item operation to update item title with “Nicer Name”, i.e. the service name defined in settings.ini, or from the spreadsheet in your case.

For step 1 and 2, a few things need to modify in the script:
1)    You need to have class AGOLHandler() return both item ID and item name. 
•    The original script only returns item ID through findItem function, you would have the function to return item name as well (see 1ReturnName.png)
•    Under def __init__, you need to modify self.itemID, self.SDitemID, and add self.itemName (see 2Self. png)
2)    Use the returned item name to create SD for overwriting the sevice         
•    Under __name__ == “__main__”:, after initialize AGOLHandler class, we will create a variable e.g. originalname, to hold item name (see 3OriginalName. png)
•    This originalname will be used to create SD (see 4CreateSD.png)
 
For step 3, you would add a block of codes to re-update the item title, using Update Item API and item name parameter, which should be straightforward.
http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Update_Item/02r30000009s000000/
http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000009v000000

Thank you Jing,
you saved me a ton of time and frustration and I believe this solution will help a lot of people with keeping their open data sites up to date.

Thank you so much, Melanie



View solution in original post

0 Kudos
1 Reply
MelanieWawryk
Frequent Contributor

Thank you to  Jing Yan from Esri Canada for figuring this one out. 

Here is the solution:

In  ArcGIS Online, the title of an item is stored in an “title” parameter (e.g. “Nicer Name”), while the original service name/SD file name is stored in a “name” parameter (e.g. “SqueezedName.sd”). 

The high-level steps are: 
1)    Use service name, e.g. “Nicer Name”, to fetch the same titled item, and then get item ID to decide which item and its SD to update. 
2)    Fetch the original service name/SD file name, e.g. “SqueezedName”, through the item name parameter, and use “SqueezedName” to create new SD and overwrite the original service. 
3)    Now the item title “Nicer Name” will be reverted back to its original service name “SqueezedName”. So the last step is to use Update Item operation to update item title with “Nicer Name”, i.e. the service name defined in settings.ini, or from the spreadsheet in your case.

For step 1 and 2, a few things need to modify in the script:
1)    You need to have class AGOLHandler() return both item ID and item name. 
•    The original script only returns item ID through findItem function, you would have the function to return item name as well (see 1ReturnName.png)
•    Under def __init__, you need to modify self.itemID, self.SDitemID, and add self.itemName (see 2Self. png)
2)    Use the returned item name to create SD for overwriting the sevice         
•    Under __name__ == “__main__”:, after initialize AGOLHandler class, we will create a variable e.g. originalname, to hold item name (see 3OriginalName. png)
•    This originalname will be used to create SD (see 4CreateSD.png)
 
For step 3, you would add a block of codes to re-update the item title, using Update Item API and item name parameter, which should be straightforward.
http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Update_Item/02r30000009s000000/
http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000009v000000

Thank you Jing,
you saved me a ton of time and frustration and I believe this solution will help a lot of people with keeping their open data sites up to date.

Thank you so much, Melanie



0 Kudos