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/
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...