HOW TO

Access and delete items on a standalone ArcGIS Server using the ArcGIS API for Python gis.server module

Last Published: April 25, 2020

Summary

When working with a standalone ArcGIS Server server, it is possible to connect to the server, find a service by its name, and delete the service using ArcGIS API for Python. This common administrative process can be automated by using the gis.server Python module via the portal when it is federated with the server.

Procedure

To access and delete items on a standalone server using the ArcGIS API for Python gis.server module, refer to the following workflow:

  1. Import the necessary modules.
import arcgis
from arcgis import *
from arcgis.gis import server
  1. Connect to the standalone server admin endpoint.
s = server.Server("<SERVERURL>/admin",username='<adminuser>',password='<adminpass>')
  1. Call the service directory
cdir = s.content
  1. Find the service that is to be deleted in its specified folder from the service directory.
serv = cdir.get("<SERVICE NAME>",folder = "<FOLDER>")
  1. Delete the service by invoking the service attribute that contains a delete method.
serv.service.delete()

If the process is successful, the system returns True at the end of the code. If the item cannot be deleted, the system returns False instead. The following is the full sample script:

import arcgis
from arcgis import *
from arcgis.gis import server

s = server.Server("<SERVERURL>/admin",username='<adminuser>',password='<adminpass>')

cdir = s.content

serv = cdir.get("<SERVICE NAME>",folder = "<FOLDER>")

serv.service.delete()

Article ID: 000021795

Software:
  • ArcGIS Server

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options