Is it possible to create an arcgis server folder with the python API within ArcGIS 10.8.1? I have tried:
gis_target = GIS(portal_url_target, portal_admin_user, portal_admin_password_target)
folder_name = "MyNewFolder"
server = gis_target.admin.servers.list()[0]
server.create_folder(folder_name)
The server object does retrieve my federated AGS. But then the call to create the folder fails.
AttributeError: 'Server' object has no attribute 'create_folder'
Solved! Go to Solution.
Hi @forestknutsen1,
You're almost there with your code, from the server object you need to access the ServiceManager via the services property and then you can use the create_folder() method.
from arcgis.gis import GIS
## access Portal
portal = GIS("home") # can also use url, username, password
## get the server of interest
server = portal.admin.servers.list()[0]
## access the server ServiceManager and create folder
status = server.services.create_folder("MY_NEW_FOLDER")
print(status) # True if successful, False if a failure.
I hope that helps.
Glen
I think you'll need admin access for this, then the Create Folder resource can take it from there. Can't think of a way to do this with the Python API though so you'll have to pick your preferred HTTP library and send those requests yourself.
The user does have admin access. And I will look into the rest api side.
Hi @forestknutsen1,
You're almost there with your code, from the server object you need to access the ServiceManager via the services property and then you can use the create_folder() method.
from arcgis.gis import GIS
## access Portal
portal = GIS("home") # can also use url, username, password
## get the server of interest
server = portal.admin.servers.list()[0]
## access the server ServiceManager and create folder
status = server.services.create_folder("MY_NEW_FOLDER")
print(status) # True if successful, False if a failure.
I hope that helps.
Glen
Ah, that did it! Thanks!