Deleting Traker Records using WEB API

Hi @jomutsani .
I need to delete 2 000 records. How can I delete by using Web API?

2 Likes

Hi @pa_trick67,

Kindly refer to the Developer’s Guide for instructions on this.

Best,
James

3 Likes

Hi Patrick,

You can delete using postman as follows:

You can try using Node JS:

let jsonPayload = {
“trackedEntityInstances”: [
{ “trackedEntityInstance”: “qWB25lSjfKd” },
{ “trackedEntityInstance”: “YGyelJBMeKy” },
{ “trackedEntityInstance”: “DiszpKrYNg8” },
{ “trackedEntityInstance”: “k4ODejBytgv” },
{ “trackedEntityInstance”: “YsKjdOcl9Cd” },
{ “trackedEntityInstance”: “wNiQ2coVZ39” }
]
}

let options = {
method: ‘POST’,
url: “https://play.dhis2.org/2.31.3/api/trackedEntityInstances?strategy=DELETE”,
body: jsonPayload,
headers: {
‘Authorization’: "Basic " + new Buffer(“admin”:“district”).toString( “base64” ),
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
from: {
mimeType: ‘application/json’
}
}; // end of options

request(options, function(error, response, body) {
console.log("Result: ", response.statusCode);
}

Note: You can prepare your jsonpayload for 2000 records.

Source: http://dhis2trainingland.com/eportal/?tutorial=deleting-tracker-records-using-web-api

Regards
Julhas

3 Likes

Hi @julhas,
I’ll give it a try.

Thank a lot.

2 Likes