I am trying to add a map service to my Portal with the ArcGIS API for Python. It works fine if I add it to the root folder but if I try to add it to a different folder it says "User folder does not exist". Obviously it exists because I just created it 2 lines earlier. I am able to do this from the Portal manager, just not from Python. Any idea what I am doing wrong?
from arcgis.gis import GIS
gis = GIS("myportal", "myaccount")
content = gis.content
content.create_folder('Basin', owner='myaccount')
properties = {
'title':'title',
'type':'Map Service',
'url':'https://.../MapServer',
'description':'description',
'tags':'tags'
}
item = content.add(item_properties=properties, owner='myaccount', folder='Basin')
Hi Eric,
What version of the ArcGIS API for Python are you running? You can check by going to ArcGIS Pro > About ArcGIS Pro > Python tab > Installed Packages > arcgis.
I tested this with 1.2.5 and ArcGIS Enterprise 10.6 and it worked successfully.
Also, are you receiving an error?
Thanks Jake.
ArcGIS API for Python version 1.2.5
ArcGIS Enterprise 10.5
Here is the full error message
RuntimeError Traceback (most recent call last)
<ipython-input-14-5dbe45519908> in <module>()
16 'tags':'tags'
17 }
---> 18 item = content.add(item_properties=properties, owner='myaccount', folder='Basin')
19
20
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py in add(self, item_properties, data, thumbnail, metadata, owner, folder)
1907 item_properties['tags'] = ",".join(item_properties['tags'])
1908
-> 1909 itemid = self._portal.add_item(item_properties, data, thumbnail, metadata, owner_name, folder)
1910
1911 if itemid is not None:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\portalpy.py in add_item(self, item_properties, data, thumbnail, metadata, owner, folder)
318
319 path += '/addItem'
--> 320 resp = self.con.post(path, postdata, files)
321 if resp and resp.get('success'):
322 return resp['id']
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py in post(self, path, postdata, files, ssl, compress, is_retry, use_ordered_dict, add_token, verify_cert, token, try_json, out_folder, file_name, force_bytes, add_headers)
1129 elif errorcode == 498:
1130 raise RuntimeError('Invalid token')
-> 1131 self._handle_json_error(resp_json['error'], errorcode)
1132 return None
1133 except AttributeError:
C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py in _handle_json_error(self, error, errorcode)
1149
1150 errormessage = errormessage + "\n(Error Code: " + str(errorcode) +")"
-> 1151 raise RuntimeError(errormessage)
1152
1153 class _StrictURLopener(request.FancyURLopener):
RuntimeError: User folder does not exist.
(Error Code: 400)
I figured out the problem. If I include owner='' then it doesn't work. If I omit it, it does.
So this does not work:
item = content.add(item_properties=properties, owner='myaccount', folder='Basin')
but this does:
item = content.add(item_properties=properties, folder='Basin')