HRHR-project / palestine

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

API: PUT of event data leads to 500 error #18

Open iambodo opened 5 years ago

iambodo commented 5 years ago

This an issue for the Palestine branch. The server responds with 500 error on both the Bangladesh and Palestine dev servers, however it works on the Play 2.29 demo.

I am trying to write a script in R to update an event (with registration) data values via PUT request. In 2.29

###packages
require(jsonlite)
require(readr)
require(assertthat)
require(httr)
##credentials
username<-"admin"
password<-"district"
baseurl<-"https://play.dhis2.org/2.29/"
if(loginDHIS2(baseurl,username,password)){
  print("successfully logged in")
}else{
  stop("could not log in! Please check url, username and password")
}
url<-paste0(baseurl, "api/events/V1CerIi3sdL")
playtest<-jsonlite::fromJSON(content(GET(url), as="text"))
##browse data values and edit one of the integer values
playtest$dataValues$value
playtest$dataValues$value[2]<-"21"
### then PUT request
httr::PUT(url = url, body=toJSON(playtest, auto_unbox=TRUE), content_type_json(), 
          httr::authenticate(username,password))

Responds with 200 status. The event record then shows data value is edited at API endpoint.

###now repeat the same in hrhr dev instance
require(jsonlite)
require(readr)
require(assertthat)
require(httr)
username<-"admin"
password<-""
baseurl<-"https://play.dhis2.org/2.29/"
if(loginDHIS2(baseurl,username,password)){
  print("successfully logged in")
}else{
  stop("could not log in! Please check url, username and password")
}
url<-paste0(baseurl, "api/events/GRrec5KoNDN")
playtest<-jsonlite::fromJSON(content(GET(url), as="text"))
playtest$dataValues$value
##small edit to an integer value
playtest$dataValues$value[1]<-"21"
httr::PUT(url = url, body=toJSON(playtest, auto_unbox=TRUE), content_type_json(), 
          httr::authenticate(username,password))

This responds with 500 status and no change to event record