Delete Features by Primary Key

Description

Deletes features in a table by passing in a collection of primary keys with an optional commitInterval. The body of the request contains the JSON representation of the primary keys. The response contains the number of features that were successfully deleted.

Note: You must have View permissions on the named table as well as Create/Modify/Delete permissions on the named table's associated dataset to perform insert, update, and delete operations on writable tables. See Users and Roles in the Administration section for more information.
Note: Delete is supported on PostGIS, Oracle, SQL Server, GeoPackage, generic JDBC tables. It also supported on MapInfo native TAB and extended native TAB (NativeX) files on Windows operating systems only (the commitInterval is ignored). The table must have a primary key or it will be considered a read-only table. Named tables with composite primary keys are not writable.

ACL Authorization Flow

To delete features in a named table by passing a collection of primary keys, the user (or the role they belong to) needs both EXECUTE and DELETE permission on the Named table.

HTTP POST URL Format

The following format is used for HTTP POST requests to delete multiple records:

HTTP POST: /FeatureService/tables/tablename/features.rep?
POST Data: action=delete&[commitInterval=c]
POST BODY: Content-Type:application/json {table delete}

The table delete is a POST json body (Content-Type: application/json) for the table delete containing primary keys to be deleted. For multiple records deleted, the json body is formatted as follows:

{ 
	“keys”: ["key1", "key2", …]
}

Parameters

For information on the parameter types listed below, see Request URL Data Types.

Parameter Type Required Description
tablename String yes The name of the table for which you are deleting features. The table is specified by a fully qualified name for the named table based on the location of the named table in the Repository. The name of the named table is defined between the /tables portion of the URL and the /features.rep portion of the URL. For example, to delete features in a named table located at /Samples/NamedTables/WorldTable in the Repository, the following URL would be used:
.../FeatureService/tables/Samples/​NamedTables
/WorldTable/features.json;... 
rep String yes The representation to be returned. Supported representation is json.
action=delete String yes The action to delete the features in the table.
commitInterval=c Integer no The number of deletes that will be processed in a transaction. For instance, if you are deleting 50 features in a table and the commitInterval is set to 20, then you will have three transactions (20, 20, 10). The default is 50. CommitInterval is ignored for native TAB and NativeX files.

HTTP DELETE URL Format

The following format is used for HTTP DELETE requests to delete a single record:

HTTP DELETE /FeatureService/tables/tablename/features.rep/key

Parameters

For information on the parameter types listed below, see Request URL Data Types.

Parameter Type Required Description
tablename String yes The name of the table for which you are deleting features. The table is specified by a fully qualified name for the named table based on the location of the named table in the Repository. The name of the named table is defined between the /tables portion of the URL and the /features.rep portion of the URL. For example, to delete features in a named table located at /Samples/NamedTables/WorldTable in the Repository, the following URL would be used:
.../FeatureService/tables/Samples/​NamedTables
/WorldTable/features.json;... 
rep String yes The representation to be returned. Supported representation is json.
key String yes The primary key for the feature to be deleted.

Returns

Returns the count of each deleted features.

Examples

Deletes the features with 6, 7, and 8 as the primary keys:

http://hostname:port/rest/Spatial/FeatureService/tables/MyTable/features.json?action=delete&commitInterval=2
   {
      "keys":["6", "7", "8"]
   }

Deletes a single feature with a primary key of 6:

http://hostname:port/rest/Spatial/FeatureService/tables/MyTable/features.json/6