BULK delete of events

We have a custom app which allows uploading of 2000+ events (without registration) from Excel file and the frequency is monthly. Say we have uploaded events for Jan 2021 and later need to upload again with updated data.

I found that bulk delete of TEI and events using strategy=DELETE has been discontinued (it was there possibly till 2.29). Now the option is to delete one by one. As we need to delete old events for that month and create new, it is quite challenging to send 2000+ API calls and ensuring they come back in reasonable time while user waits in front-end.

I also found that we can set deleted=true in table programstageinstance where the events are stored. But question is - how to send update SQL command directly to backend from web app?

@Mahmud To answer your question, it is not possible to send update SQL command directly to backend from web app. SQL commands can be executed directly on the database if you have access to it. For example, by using pgadmin or psql and connecting to the db directly.

But bulk delete of TEI and events using importStrategy=DELETE should still be supported. Web API - DHIS2 Documentation This is the documentation for 2.34. But it should still be supported. Did you face any issue when trying to bulk delete as mentioned in the attached documentation link?

1 Like

It is in documentation, but believe me, we had passed sleepless nights to understand why it is not working. There is no ‘importStrategy’ but ‘strategy’ is a valid keyword.

In the following screen you see I am passing 2 event ids -

The returned success message shows 2 events are deleted -

        "responseType": "ImportSummaries",
        "status": "SUCCESS",
        "imported": 0,
        "updated": 0,
        "deleted": 2,

But actually nothing happens in the database. If you query and go inside database you see that the event records are not touched.

If you give the call with 1 event -

Then the deleted flag is set. Our instance is 2.35 under docker.

@Mahmud That is interesting and it looks like a bug. Please create a jira issue with all the necessary details and specific version numbers and we will definitely look into it and hopefully resolve it.
In the meantime, directly accessing the db might be the only choice.

1 Like

Hi @Ameen
We are delivering a web app that allows uploading monthly events. Directly accessing the DB is out of scope. To the Ministry it will be treated as - the app not working as you upload 2 times and records will continue to grow.

Anyway, will see what to do.

@Mahmud In that case, it would help us if you can create a jira issue with all the necessary details. We can try to prioritize it and resolve the issue for the next patch release. You can share the jira issue in this thread once its created.

1 Like


When we do deletes in DHIS2 tracker, they are primarily soft-deletes. You can run a routine to hard delete them another place.

Can you check the database records and see if the records have their “deleted” column set to “true”?

@Stian nothing happens after bulk delete, deleted flag is not set. We do not realy need hard delete from database. As long as soft delete happens and it is not displayed in the front end it would be fine. Which is not happening when multiple event IDs are sent in the API.

@Mahmud Please create a jira issue with the details and share it in this thread. We will prioritize and release it in a patch as early as possible.

Hi @Mahmud,

there is another option you can use in the meanwhile for versions >= 2.30. This endpoint accepts a SYNC strategy that allows to create, delete and update events in a single query (/api/events?strategy=SYNC). You just have to set the property deleted to false in the event payload ({ deleted: true }).



with parameter -

	"events": [
        { "event": "Aukfl3mu5bW", "deleted": true },
        { "event": "IpG2ZIbkQwF", "deleted": true  }		

The same bug. If I give 1 event, it gets deleted immediately - but 2 does not.

Which version are you using? I have just tested it with 2 events in 2.36.3 and it is working fine, both events are soft-deleted.

@vgarciabnz and @Ameen
We were using 2.35 and upgraded to 2.36 and found that the bulk delete is working as expected.

1 Like