Delete Field from Feature Layer

03-14-2019 09:31 PM
New Contributor III


I have been trying to delete a field from a feature layer. I have tried "delete_from_definition" and I get a success response, and yet the field (column) is still there afterwards: 

1. I have a layer object, named updater_layer (it is definitely a feature layer object, I have checked its properties).  

2. I create the JSON that defines the column: 

status_remove = {
"name" : "STATUS",
"type" : "esriFieldTypeString",
"alias" : "Status",
"sqlType" : "sqlTypeOther",
"length" : 35,
"nullable" : 'true',
"editable" : 'true',
"domain" : 'null',
"defaultValue" : 'null'

3. I use:


{'success': True}

but when I look at the properties i.e.

The STATUS field is still there. 

How do I remove a field from a feature layer in ArcGIS Online using the arcgis.gis API? 



0 Kudos
2 Replies
New Contributor III

Hello Hugo, 

Here is how you would delete a field from a feature layer hosted in AGOL. 

import arcgis
from arcgis.gis import GIS

# Provide credentials to the GIS object.
gis = GIS(username="your username", password= "your password")

#Get the id of the hosted feature layer
item = gis.content.get("id to the feature layer")

#Get the actual feature layer
fl = item.layers[0]

#This is the JSON structure you need to pass in so that it knows what field to delete. 
json = {
    "fields" : [
      "name" : "POP90_SQMI"

result = fl.manager.delete_from_definition(json)
New Contributor II

i am sorry an still new in this. Where i can run this code. can you please tell me what to do.

0 Kudos