0

I am trying to delete some features from a feature service using an ArcGIS REST API. This documentation shows the output, but I am trying to work out the input. I want to do this via code, rather than via the web interface.

I have tried these JSON parameters: {'objectids': [4, 5, 6]} and {'deleteResults': [{'objectId': 4, 'f': 'json'}]} but they don't work.

Any ideas?

Ideally I would be deleting the features via Python. Can you do it without the API? I can post and query the feature service without accessing the 'ArcGIS API for Python' (e.g. using requests and urllib).

This is a sample form.

3
  • Something like this seems to work: {'objectids': [{8, 802, 803}]} Sep 19, 2023 at 6:36
  • It would surprise me if this format really works, it isn't even valid json
    – Berend
    Sep 19, 2023 at 7:54
  • It is a version of something that I used for adding features. It sort of works, it deletes the second and third features, but not the first. I could definitely be improved. Sep 19, 2023 at 22:35

1 Answer 1

2

The format is just a comma separated list of objectids, no JSON.

The page you linked to has an example:

The object IDs of the layer or table to be deleted.

Syntax: objectIds=<objectId1>, <objectId2>

Example: objectIds=37, 462

So you need to make a POST request to: https://example.com/arcgis/rest/services/MyService/0/deleteFeatures, with objectIds=37,462 in the request body

The easiest way to check the format of such requests is to use the html interface of the service. Open https://example.com/arcgis/rest/services/MyService/0?f=html in a browser, then click on Delete Features, enter some ID's: 1,2,3,4 and use the F12 Developer Tools to see the actual request

3
  • Thanks. I will give it a go a bit later. Sep 19, 2023 at 22:35
  • I couldn't work out where in the Developer Tools to see the format of the request, but I edited the JSON posted based on your advice. Sep 20, 2023 at 1:35
  • 1
    It's on the Network tab
    – Berend
    Sep 20, 2023 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.