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

3390
4
10-01-2012 01:21 AM
RobertWard
New Contributor
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)
    else:
        arcpy.SetParameter(6, False)
        arcpy.AddError(status)
        
    return


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:

http://server:port/arcgis/admin/data/registerItem
 item={
  "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?
Tags (2)
0 Kudos
4 Replies
KevinGooss
Occasional Contributor
Is that toolset exposed in ArcCatalog? I seem to recall that it is only available as python tools.
but if it were a tool in ArcCatalog you could run it from there and see the python being cranked out.
0 Kudos
RobertWard
New Contributor
Is that toolset exposed in ArcCatalog? I seem to recall that it is only available as python tools.
but if it were a tool in ArcCatalog you could run it from there and see the python being cranked out.


Tried that trick for some other tasks but I can't find a tool to register a geodatabase with an ArcGIS Server.
0 Kudos
PatriceFREYDIERE
New Contributor II
There is a System GeoProcessor that aim to get the connectionstring from the .sde file, and permit to register by script the database.

1 - upload the .sde file using uploads admin rest endpoint
2 - use the /"Get Database ConnectionString" Geoprocessing function of the PublishingTools 's System folder
     -> using fiddler you can trace the parameters and calls from the manager.


3 - Register the database with proper JSON String using /registerItem
0 Kudos
KevinHibma
Esri Regular Contributor
I know the question asks specifically how to use the REST Admin to register a data source -
However at 10.1 SP1 we added the following to arcpy:

AddDataStoreItem
ListDataStoreItems
RemoveDataStoreItem
ValidateDataStoreItem

Hopefully you find these as an easier and more straight forward approach to adding items to the data store.
0 Kudos