amit
20 April 2021 16:57
1
Hi all,
I am developing an API to read/write to an event. I am able to GET an event but when I do a PUT or PATCH, I get error 405 (Method Not Allowed).
I am using dhis2 version 2.33 and using the default admin/district account to communicate with the API
http://dhis2.example.com/api/events/CANH8cUpg1i?mergeMode=MERGE&strategy=UPDATE
I tried with mergeMode=MERGE&strategy=UPDATE and without them
Is there something I am missing?
Gintare
(Gintare)
21 April 2021 09:38
2
Hey @amit ,
PATCH is not supported by /events
endpoint, but PUT should work fine. Tracker capture app uses PUT to update event data values.
Another way would be to just POST to /events?mergeMode=merge&strategy=UPDATE
. Your json body (event array) should contain events with ids then.
Gintare
amit
21 April 2021 11:49
3
Thank you for your response. Really appreciate it.
I tried POST with ?mergeMode=merge&strategy=UPDATE but I am still getting 405 error
My data format is like this
$data = '{
"events": [{
"program": "dg7FLdagtvI",
"event": "CQNH8xYpg1i",
"dataValues": [{
"dataElement": "PfKTVVAoklK",
"value": "AMC94237"
}]
}]
}';
Gintare
(Gintare)
22 April 2021 09:40
4
@amit ,
Your payload structure looks correct. Could you share the full URL you are using? The error you are getting would only make sense if you are trying to POST to /events/id
, but not /events
.
Gintare
amit
22 April 2021 14:43
5
@Gintare
I was sending it to /events/id
sending POST to /events worked but it removed all the other dataElements and just “PfKTVVAoklK” remains now. I just wanted to update this particular dataElement while retaining the rest as it is.
Once again, thank you for your help
amit
22 April 2021 16:29
6
@Gintare
How do I just update some of the elements?