How to Register Geodatabases with ArcGIS Server using REST Server Admin API

Discussion created by rob3rtward on Oct 1, 2012
Latest reply on Nov 6, 2012 by khibma-esristaff
I'm trying to register a geodatabase with an ArcGIS server using a Python script but there is very little documentation on how to do it.

The script I have at the moment is:

# Function to register a geodatabase with an ArcGIS Server
def registerGeodatabase(server, port, geodatabase, adminUser, adminPass, token=None):
    addCustMsg("Registering geodatabase : " + geodatabase)
    # Get and set the token
    if token is None:    
        token = gentoken(server, port, adminUser, adminPass)    

    prop_dict = { "type": "egdb",
                        "path": "/enterpriseDatabases/" + geodatabase,
                        "id": "",
   "clientPath": ""
    wrapper_dict = { "item": prop_dict }
    wrapper_encode = urllib.urlencode(wrapper_dict)

    print wrapper_encode
    create = "http://{}:{}/arcgis/admin/data/registerItem?token={}&f=json".format(server, port, token)    
    status = urllib2.urlopen(create, wrapper_encode).read()
    if 'success' in status:
        arcpy.SetParameter(6, True)
        arcpy.SetParameter(6, False)

From registering a geodatabase to the ArcGIS server using the ArcGIS manager I have worked out I need to upload the database connection file using:

Register Item - http://server:port/arcgis/admin/uploads/register
Upload Part - http://server:port/arcgis/admin/uploads/<itemID>/uploadPart
Commit Item - http://server:port/arcgis/admin/uploads/<itemID>/commit

The database connection file will have an itemID to uniquely identify it, how to I reference the database connection file in the RegisterDataItem REST call:

  "path": "<path>",
  "type": "<datadir|folder|fgdb|egdb|dataset>",
  "id": "<id>",
  "clientPath": "<client-path>"

Using the ArcGIS Manager to register the geodatabase suggests it extracts the contents of the uploaded database connection file into a string but I can't find how this is done.

Any suggestions?