Bulk delete events using the Capture app

Hey there! I’m working on this in 2025 with v. 2.41.0.1

I have over 6k events to delete and at current, the Import/Export app does not allow importing with the delete option as it did in previous versions.

I’d like to inquire what is the payload structure supposed to be for posting the values to be deleted? The documentation is not explicit on what is required, my test values are getting ignored and also some values stating that they do not exist or are missing.

what is absolutely required? As you can tell from the bulk of events, I want to include only the absolutely necessary values.

Request:

POST: http://xxx.org:8080/api/tracker?async=false&reportMode=full&importMode=validate

Sample Payload:

{
"events": [
  {
    "event": "kkQTNM29wA9",
    "program": "zVILtFVUOrz",
    "programStage": "ehUbv26vzfp",
    "orgUnit": "AAFatuPTWOr",
    "trackedEntity": "M6qTyL4Qp8N",
    "enrollment": "CukAB9gebRj",
    "deleted": true
  },
  {
    "event": "M8eTyL4Qp8N",
    "program": "zVILtFVUOrz",
    "programStage": "ehUbv26vzfp",
    "orgUnit": "AAFatuPTWOr",
    "trackedEntity": "M6qTyL4Qp8N",
    "deleted": true
  },
  {
    "event": "M8dTyL4Qp8N",
    "program": "zVILtFVUOrz",
    "programStage": "ehUbv26vzfp",
    "orgUnit": "AAFatuPTWOr",
    "trackedEntity": "M6pTyL4Qp8N",
    "deleted": true
  },
  {
    "event": "M8cTyL4Qp8N",
    "program": "zVILtFVUOrz",
    "programStage": "ehUbv26vzfp",
    "orgUnit": "AAFatuPTWOr",
    "trackedEntity": "M6nTyL4Qp8N",
    "deleted": true
  },
  {
    "event": "M8bTyL4Qp8N",
    "program": "zVILtFVUOrz",
    "programStage": "ehUbv26vzfp",
    "orgUnit": "AAFatuPTWOr",
    "trackedEntity": "M6mTyL4Qp8N",
    "deleted": true
  }
]
}

Server Response: 409 Conflict

{
    "status": "ERROR",
    "validationReport": {
        "errorReports": [
            {
                "message": "Missing required event property: `program`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "kkQTNM29wA9",
                "args": [
                    "program"
                ]
            },
            {
                "message": "Missing required event property: `programStage`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "kkQTNM29wA9",
                "args": [
                    "programStage"
                ]
            },
            {
                "message": "Missing required event property: `program`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "M8eTyL4Qp8N",
                "args": [
                    "program"
                ]
            },
            {
                "message": "Missing required event property: `orgUnit`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "M8eTyL4Qp8N",
                "args": [
                    "orgUnit"
                ]
            },
            {
                "message": "Missing required event property: `programStage`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "M8eTyL4Qp8N",
                "args": [
                    "programStage"
                ]
            },
            {
                "message": "Missing required event property: `orgUnit`.",
                "errorCode": "E1123",
                "trackerType": "EVENT",
                "uid": "kkQTNM29wA9",
                "args": [
                    "orgUnit"
                ]
            }
        ],
        "warningReports": []
    },
    "stats": {
        "created": 0,
        "updated": 0,
        "deleted": 0,
        "ignored": 2,
        "total": 2
    }
}

Hey @lillian1n2

Why is it saying ‘Missing required event property’? For these events you’re trying to delete using the API, do you have the permissions to delete the at least one event using the UI? What is the authorization/token permissions for the user’s API requests?

Hi @lillian1n2,

One thing you could utilize is the new bulk operations in the Capture app. In this way you can delete 100 events at a time at least, which is maybe still a bit more time consuming than you’d like, but you would be able to filter on what program, program stage and other parameters before choosing what to delete too.

1 Like

To be clear, I am using a superuser account which has full authorities esp over event and TEI data.

I also pulled all the data in .csv format from the Import/Export app so those values are values I retrieved and formatted into the JSON payload in order to see server response as I worked out both the payload structure as well as the specific arguments to be used in the API call.

1 Like

This works! Thank you!

1 Like

Great to hear @lillian1n2 - this is actually a pretty new functionality so let me know if you have any feedback on the usability :blush:

1 Like

I might also suggest using a runner in Postman; this allows for iterative DELETE runs using an {{id}} tag on /api/events/{{id}} and inserting an array of [{“id”:“XXX”},{“id”:“YYY”}] where XXX and YYY are event UIDs. In this way, all you’d need are the event UIDs. We’ve found Postman to be very convenient and “light” way to delete what we’ve needed.

1 Like

@lillian1n2
We’ve also done some investigation but it doesn’t seem like this was previously supported; however as @Karoline suggested, we can create a feature request for this:

Bulk Delete Events using Import/Export app - Event Import – DHIS2-19036

Thanks!

Yes, true! I’ve tried Runner on Postman several times (while not exactly for deleting events) but it’s very light way to process a number of API requests. Thanks for sharing your insights! :slight_smile: