Data value deletion through API - DELETE Method not allowed error

Hello Community

Have been trying ways to delete a particular data value for a particular period. But was always getting below error.

{"httpStatus":"Method Not Allowed","httpStatusCode":405,"status":"ERROR","message":"Request method 'DELETE' not supported"}

Commands I tried:
curl '../api/dataValueSets?de=A4dYKbXigYt&pe=202005&ou=rxpNKF22FFs&co=HllvX50cXC0' -X DELETE -u <user>:<pass>

curl '../api/dataValueSets?dataValueSets.json?dataSet=ijBxmyvP7Jb&period=202005&orgUnit=rxpNKF22FF' -X DELETE -u <user>:<pass>

Request your support. My intention is to delete particular values whenever need (not bulk deletion)

1 Like

Hi @jthomas,

Thanks for your question! If you are trying to delete individual data values, i would recommend using /dataValues endpoint. You can read about the endpoint here.

Your request could look something like that:
curl '../dataValues?ou=rxpNKF22FF&pe=202005&ds=ijBxmyvP7Jb&de=A4dYKbXigYt' -X DELETE -u <user>:<pass>

Gintare

1 Like

Thanks @Gintare It worked for me.

Happy to hear @jthomas!

1 Like

Hi @Gintare ,
I am trying to delete list of items from optionGroupSets. JSON payload created the list like:
{
“deletions”: [
{
“id”: “qLKyJBlKqoU”
},
{
“id”: “dKy5htKtIaA”
}]}

pointed to the http://localhost:8080/dhis/api/optionGroupSets?strategy=DELETE
but got an error:
{

"httpStatus": "Conflict",

"httpStatusCode": 409,

"status": "ERROR",

"message": "One more more errors occurred, please see full details in import report.",

"response": {

    "responseType": "ObjectReport",

    "uid": "nnj8i1tNniF",

    "klass": "org.hisp.dhis.option.OptionGroupSet",

    "errorReports": [

        {

            "message": "Missing required property `name`.",

            "mainKlass": "org.hisp.dhis.option.OptionGroupSet",

            "errorCode": "E4000",

            "errorKlass": "java.lang.String",

            "errorProperty": "name",

            "errorProperties": [

                "name"

            ]

        }

    ]

}

}

I am using Postman. method: POST, header: Content-Type application/json, body : raw/JSON.

How can I bulk delete optionSets optionValues, optionSets and optionGroupSets?
Later I may need to delete PRs, PRactions, DE and programStageSectionDE

Thank you.
Regards, Ulanbek

Hey @Ulanbek ,

I think /metadata endpoint should work better for your use case. That endpoint accepts both list of objects and importStrategy=DELETE query param.

Your payload would look something like that:

{
  "optionGroupSets": [
		{
			"id": "VQ2lai3OfVG"
		},
		{
			"id": "..."
		}
  
  ],
  "optionSets": [{ .. }] // if you want to delete more metadata objects
}