Get MXD path property for a service published on ArcGIS Server with python?

3270
6
Jump to solution
07-21-2020 11:14 PM
lxd
by
New Contributor III

Is there a way to programically (probably python?) to get the path property of a service published to an ArcGIS Server?

I found this piece of python:

for dir in [None] + SD.folders:
for srv in SD.list(folder=dir):
print(str(srv.properties))

It gets properties of the services (seems to be the same as you can get by going to the rest end point), but none of these properties is the original mxd path.. 

1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Give the following code a try, but it only works in ArcGIS API for Python < 1.8.0.  There is a defect in the 1.8.x release that messes up the connection objects for stand-alone GIS servers.

from arcgis.gis.server import Server
from getpass import getpass
import json

url = # URL to ArcGIS Admin API, e.g., https://fqdn:port/arcgis/admin
username = # username of user with administrative privileges

server = Server(url=url, username=username, password=getpass(), verify_cert=False)
sm = server.services
svcs = (
    svc 
    for fld in sm.folders 
    for svc in sm.list(fld)
    if fld not in ['System', 'Utilities']
)
for svc in svcs:
    name = svc.serviceName
    
    manifest = json.loads(svc._service_manifest())
    if manifest.get("code", 200) == 200:
        mxd_path = manifest["resources"][0]["onPremisePath"]
    else:
        mxd_path = "Service does not include path information."
    
    print("{:<40}{}".format(name, mxd_path))

View solution in original post

6 Replies
Arne_Gelfert
Occasional Contributor III

What I have done in the past and seen explained elsewhere is going to the services directories on the machine your GIS Server is installed on. That's provided you have access to that. Typically you will find the path to the original MXD there:

EXAMPLE

\<arcgisserver_install_dir>\directories\arcgissystem\arcgisinput\<service_folder>\<service_name>.MapServer\extracted\manifest.json

JSON would look something like this:

{"databases":[{
    "byReference":true,
    "onServerWorkspaceFactoryProgID":".,...",
    "onServerConnectionString":"....",
    "onServerName":"....",
    "onPremisePath":"",
    "datasets":[{"onServerName":" ...."}]
    }],
    "resources":[{"onPremisePath":"<<<<<<<path to .MXD file>>>>>>>",
        "clientName":"....",
    "serverPath":"<path to .msd file>"}
    ]}‍‍‍‍‍‍‍‍‍‍‍‍
lxd
by
New Contributor III

Thank you Arne Gelfert. Unfortunately we don't have access to the actual machine. It is run for us by ESRI. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Give the following code a try, but it only works in ArcGIS API for Python < 1.8.0.  There is a defect in the 1.8.x release that messes up the connection objects for stand-alone GIS servers.

from arcgis.gis.server import Server
from getpass import getpass
import json

url = # URL to ArcGIS Admin API, e.g., https://fqdn:port/arcgis/admin
username = # username of user with administrative privileges

server = Server(url=url, username=username, password=getpass(), verify_cert=False)
sm = server.services
svcs = (
    svc 
    for fld in sm.folders 
    for svc in sm.list(fld)
    if fld not in ['System', 'Utilities']
)
for svc in svcs:
    name = svc.serviceName
    
    manifest = json.loads(svc._service_manifest())
    if manifest.get("code", 200) == 200:
        mxd_path = manifest["resources"][0]["onPremisePath"]
    else:
        mxd_path = "Service does not include path information."
    
    print("{:<40}{}".format(name, mxd_path))

lxd
by
New Contributor III

Thank you Joshua Bixby‌, your code worked a trick and I got exactly what I needed. Is there a documentation on that somewhere? would be great to see what else I can do. Thanks again!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

In terms of the ArcGIS API for Python, reviewing arcgis.gis.server module — arcgis 1.8.2 documentation would be good.  Unfortunately, most of the Guide and Sample Notebooks focus on federated ArcGIS Enterprise deployments, so they don't apply well to stand-alone ArcGIS Enterprise deployments.  The product team for ArcGIS API for Python has taken a different approach to documentation than other Esri product teams, so their documentation has a different structure and different levels of content than other Esri documentation.  Personally, I think it is a step backwards both in structure and content.

Since the ArcGIS API for Python is mostly a Python wrapper for the ArcGIS REST API | ArcGIS for Developers , I encourage you to learn as much about the REST API as you can because I often find myself learning the API for Python by working backwards from the REST API.  For administrative options, you would want to read up on the Administrator API of the ArcGIS REST API.

0 Kudos
DavidPike
MVP Frequent Contributor

@JoshuaBixby  this worked a treat for me and saved me poring over the cursed python api documentation, thanks!

0 Kudos