Select to view content in your preferred language

Create an arcgis server folder with the python API?

232
4
Jump to solution
3 weeks ago
forestknutsen1
MVP Alum

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'

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
MVP Regular Contributor

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

~ learn.finaldraftmapping.com

View solution in original post

4 Replies
DavidSolari
MVP Regular Contributor

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.

0 Kudos
forestknutsen1
MVP Alum

The user does have admin access. And I will look into the rest api side.

0 Kudos
Clubdebambos
MVP Regular Contributor

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

~ learn.finaldraftmapping.com
forestknutsen1
MVP Alum

Ah, that did it! Thanks!

0 Kudos