Skip To Content ArcGIS for Developers Sign In Dashboard

Overview

You will learn: how to add, edit, and remove features from ArcGIS Feature Services.

ArcGIS Feature Services can access, edit, and store spatial data in feature layers. Feature layers define the spatial reference, geometry type (points, lines or polygons), attribute fields, and the permission settings for the data. If you want to create an application that can edit feature layer data you can use the ArcGIS REST API and the applyEdits operation. All you need to do is either pass in the features to create or update, or pass in the ObjectIDs to delete, and the service will perform the operation. To learn more about the capabilities of feature services, please visit the documentation.

In this tutorial you will use the ArcGIS REST API to access a hosted feature layer to add, edit and remove features.

Before you begin

Install Postman to execute HTTP requests. Go to this tutorial if you need an access token.

Create a feature layer to edit

To complete this tutorial you will need at least one editable feature layer.

  1. If you have not completed the Create a new dataset tutorial, go to the tutorial and follow the steps to create a new feature layer. You will only need the My Points feature layer in this tutorial.

Get the feature layer URL

  1. If you are not signed in, sign in to the ArcGIS for Developers website now.

  2. Go to ArcGIS for Developers/layers and click My Points. Use the feature layer property page to find and copy the Service URL value for the layer. This URL will be used in later steps. Here's an example:

    • Service URL: https://services.arcgis.com/<your ID>/arcgis/rest/services/my_points/FeatureServer

Steps

Create a request to access the feature service

  1. Open Postman and click [+] in the tab bar to create a new request.

  2. In the new tab, set the following:

    • HTTP Method: POST
    • Request URL: Paste in your layer URL from above and add /0/applyEdits to the end. It should look something like this:

    https://services.arcgis.com/<your ID>/arcgis/rest/services/my_points/FeatureServer/0/applyEdits

Add parameters to add a new feature

  1. Click on Body > x-www-form-urlencoded and add the following Key/Value pairs:

    • f: json
    • token: A token from the Get an access token tutorial.
    • adds:
      [
        {
          "geometry" : {
            "x": -118.80657463861,
            "y": 34.0005930608889,
            "spatialReference": {
              "wkid": 4326
            }
          },
          "attributes" : {
            "ID" : "100",
            "Name" : "My Point",
            "Rating" : "Good"
          }
        }
      ]
      
  2. Click Send to run the request.

  3. In the response window, click Pretty > JSON. It should look something like this:

    {
      "addResults": [
          {
              "objectId": 1,
              "uniqueId": 1,
              "globalId": null,
              "success": true
          }
      ],
      "updateResults": [],
      "deleteResults": []
    }
    
  4. Find the objectId in the response. This is the unique ID of the feature you will use in the next steps.

Update the parameters to edit an existing feature

  1. In the Body, remove the adds parameter and add the updates parameter and change the field values to the following:

    • updates:
    [
      {
        "attributes" : {
          "objectId": 1,
            "ID" : "101",
            "Name" : "Awesome Beach",
            "Rating" : "Excellent"
        }
      }
    ]
    
  2. Click Send to run the request.

  3. In the response window, click Pretty > JSON. It should look something like this:

    {
      "addResults": [],
      "updateResults": [
          {
              "objectId": 1,
              "uniqueId": 1,
              "globalId": null,
              "success": true
          }
      ],
      "deleteResults": []
    }
    

Update the parameters to delete a feature

  1. In the Body, remove the updates parameter and add a deletes parameter. Set it to the following:

    • deletes: The objectId of the feature from step 6.
    [
      1
    ]
    
  2. Click Send to run the request.

  3. In the response window, click Pretty > JSON. It should look something like this:

    {
      "addResults": [],
      "updateResults": [],
      "deleteResults": [
          {
              "objectId": 1,
              "uniqueId": 1,
              "globalId": null,
              "success": true
          }
      ]
    }
    
  1. In Postman click Code below the Send button. Select a programming language and use Postman to generate sample code for your application to run this request.

Congratulations, you're done!

You have successfully added, edited, and removed a feature from a feature service.

Challenge

Add, edit, or delete features in bulk with applyEdits

Try using the applyEdits operation on a feature layer to add, edit, and delete features in a single request.

Configure editing settings

Feature layer editing permissions are highly configurable. Sign in to ArcGIS for Developers and click dashboard > View All Layers and find the "My Points" layer you created in the Create a new dataset tutorial. click Settings and explore the Permissions Settings.

As the layer's owner, these permission settings do not apply to you. However, they impact other users if you make your layer public or share it with any other ArcGIS Online users.

Editing a public layer

Feature layers can be made public and edits can be done by unauthenticated users without the need of a token. Try the Share maps and layers tutorial and share your layer publicly. You will be able to omit the token parameter in your requests.