Hi everyone,
I am trying to debug an API request.
I’m getting an error when creating an Observation. This is the request being sent to OpenMRS:
POST https://www.example.com/openmrs/ws/rest/v1/obs
{
"concept": "f09e9b39-d83e-4cdb-b590-f39626f0708b",
"encounter": "f109efe8-bffb-4eb3-b972-a2e90b1dd3c0",
"location": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
"obsDatetime": "2019-09-12T11:11:12.941+0000",
"person": "f287b47a-3827-4c11-a35f-13dc8e783c4b",
"value": true
}
OpenMRS is responding with status code 400:
{
"error": {
"code": "org.openmrs.module.webservices.rest.web.ConversionUtil:409",
"detail": "org.openmrs.module.webservices.rest.web.response.ConversionException: converting class org.openmrs.Obs to org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation@27507c1
at org.openmrs.module.webservices.rest.web.ConversionUtil.convertToRepresentation(ConversionUtil.java:409)
...",
"message": "[converting class org.openmrs.Obs to org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation@27507c1]"
}
}
I took a look at the source code, and based on the data type, org.openmrs.Obs, it seems the Observation has been created successfully before this error occurs. If we check the database, we can confirm that it is being created. We can fetch it using the API. e.g.
GET https://www.example.com/openmrs/ws/rest/v1/obs/409a5817-8980-4f7c-9c93-abca3b641080?v=ref
{
"uuid": "409a5817-8980-4f7c-9c93-abca3b641080",
"display": "U2-Abnormal temperature: true",
"links": [
{
"rel": "self",
"uri": "https://www.example.com/openmrs/ws/rest/v1/obs/409a5817-8980-4f7c-9c93-abca3b641080"
}
]
}
Any idea what is causing the error, and how to avoid it?
Let me know if the full stacktrace would help, or the full details of the Observation that’s created.
Kind regards,
Norman