Select to view content in your preferred language

Create folder in ArcGSI Server

166
1
01-13-2025 04:49 PM
Labels (1)
forestknutsen1
MVP Alum

I am trying to create ArcGIS Server folders with the rest API. This is what I have tried:

def create_folders(admin, password):
    url = 'https://xyzx.com:6443/arcgis/admin/services/createFolder'
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    payload = {'folderName': 'my_test'}
    auth = (admin, password)
    response = requests.post(url, headers=headers, json=payload, auth=auth)
    print(response.json)

The print statement is dumping out <bound method Response.json of <Response [200]>> and no folder is created.

https://developers.arcgis.com/rest/enterprise-administration/server/createfolder/

 

 

0 Kudos
1 Reply
forestknutsen1
MVP Alum

I got it to work with python 2

import json
import urllib2
from urllib import urlencode

data = {
    'username': 'xyzx',
    'password': 'xyzx',
    'client': 'requestip',
    'expiration': 15,
    'f': 'json'
}
url = 'xyzx.com:6443/arcgis/admin/generateToken'
post = urlencode(data)
req = urllib2.Request(url, post)
response = urllib2.urlopen(req)
json_response = response.read()
json_response = json.loads(json_response)
token = json_response['token']

data = {
    'token': token,
    'folderName': 'my_test',
    'f': 'json'
}
url = 'xyzx.com:6443/arcgis/admin/services/createFolder'
post = urlencode(data)
req = urllib2.Request(url, post)
response = urllib2.urlopen(req)
json_response = response.read()
json_response = json.loads(json_response)

Maybe I needed to create a token first with my python 3 attempt... 

0 Kudos