dhis2-users team mailing list archive
-
dhis2-users team
-
Mailing list archive
-
Message #15201
Re: Posting Metadata in dhis2.
Hi Isaiah,
You have
"parent":"vpiZlB5cdK7"
It should be
parent":{"id":"vpiZlB5cdK7"}}
Be sure your JSON structure is exactly as it should be, otherwise, you will
get those kinds of errors. Study the example here
<https://raw.githubusercontent.com/jason-p-pickering/dhis2-data-munging/master/ous/ous.json>
.
Regards,
Jason
On Thu, Feb 15, 2018 at 1:07 PM, Isaiah Nyabuto <isaiahnyabuto@xxxxxxxxx>
wrote:
> Thank you for the tip. It still doesn't work.
> what does this error mean?
>
> httr::content(r, "text")
>
> [1] "{\"httpStatus\":\"Internal Server Error\",\"httpStatusCode\":500
> ,\"status\":\"ERROR\",\"message\":\"Can not instantiate value of type
> [simple type, class org.hisp.dhis.organisationunit.OrganisationUnit] from
> String value ('It7fWcKbcZX'); no single-String constructor/factory
> method\\n at [Source: org.apache.catalina.connector.
> CoyoteInputStream@1efec811; line: 1, column: 73] (through reference
> chain: org.hisp.dhis.organisationunit.OrganisationUnit[\\\"parent\\\
> "])\"}"
>
> Anyone?
>
> Thank you.
> ==========================
> Isaiah Nyabuto
> +254729572616 <+254%20729%20572616>
> Bsc. Health Records Management and Informatics
>
> On Feb 15, 2018 13:14, "Jason Pickering" <jason.p.pickering@xxxxxxxxx>
> wrote:
>
> All of your fields must have exactly the correct names:
>
> shortname -> shortName
> featuretype-> featureType
>
> Keep hacking at it! You will get there!
>
> Regards,
> Jason
>
>
> On Thu, Feb 15, 2018 at 11:08 AM, Isaiah Nyabuto <isaiahnyabuto@xxxxxxxxx>
> wrote:
>
>> Hi Jason,
>>
>> Here is some bit of my post data.
>>
>> {"organisationUnits":[{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5","code":"16925","parent":"vpiZlB5cdK7","shortname":"Wikithuki Dispensary","description":"","comment":"","featuretype":"POINT","coordinates":"[37.95263,-0.77819]","url":""},{"name":"Gemifa Medical Clinic","uid":"Z7Lf1n3Fcpi","code":"22907","parent":"mEZBjj4fLBT","shortname":"Gemifa","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.391914,0.059575]","url":""},{"name":"Olympus Medical Clinic","uid":"NAbQdHuaJFK","code":"22906","parent":"PeEcMfBchbr","shortname":"Olympus","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.3994,0.059575]","url":""},{"name":"Masaba Community Health Unit","uid":"tYwHeLSnHyb","code":"600616","parent":"QR2K4k8VKF1","shortname":"Masaba CHU","description":"Community Unit","comment":"","featuretype":"NONE","coordinates":"[34.46411,0.19358]","url":""},{"name":"Gatunga Health Centre","uid":"cmay4WXRmhA","code":"12034","parent":
>>
>>
>> After changing the "uid" to "id", still it doesn't work.
>>
>> Thank you
>>
>>
>> On Thu, Feb 15, 2018 at 12:14 PM, Jason Pickering <
>> jason.p.pickering@xxxxxxxxx> wrote:
>>
>>> Hi Isaiah,
>>>
>>> Post a bit of your JSON here from toJSON(list(organisationUnits=new_org),
>>> auto_unbox = TRUE)
>>>
>>> One other problem I noticed as well is this
>>>
>>> [{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5"
>>>
>>>
>>> It should be
>>>
>>> [{"name":"Wikithuki Dispensary","id":"Bc371uxfYD5"
>>>
>>>
>>> Regards,
>>> Jason
>>>
>>>
>>> On Thu, Feb 15, 2018 at 10:01 AM, Isaiah Nyabuto <
>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>
>>>> Hi Jason,
>>>>
>>>> I get an internal server error code: 500, after trying that. Here is
>>>> the response;
>>>>
>>>> httr::content(r, "text")[1] "{\"httpStatus\":\"Internal Server Error\",\"httpStatusCode\":500,\"status\":\"ERROR\",\"message\":\"Can not instantiate value of type [simple type, class org.hisp.dhis.organisationunit.OrganisationUnit] from String value ('It7fWcKbcZX'); no single-String constructor/factory method\\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1efec811; line: 1, column: 73] (through reference chain: org.hisp.dhis.organisationunit.OrganisationUnit[\\\"parent\\\"])\"}"
>>>>
>>>>
>>>> Thank you.
>>>>
>>>> On Thu, Feb 15, 2018 at 10:36 AM, Jason Pickering <
>>>> jason.p.pickering@xxxxxxxxx> wrote:
>>>>
>>>>> Hi Isiah,
>>>>>
>>>>> The reason for it not working (at least at first glance) is that you
>>>>> are posing to the /api/metadata endpoint. Thus, you need to tell the server
>>>>> what you are trying to import. In this case, its organisation units.
>>>>>
>>>>> I think changing this to
>>>>>
>>>>> r <- POST(url, authenticate(dest.user, dest.pass),
>>>>> body = toJSON(list(organisationUnits=new_org), auto_unbox
>>>>> = TRUE),
>>>>> content_type_json())
>>>>>
>>>>> should work.
>>>>>
>>>>> The example works because the file
>>>>> <https://raw.githubusercontent.com/jason-p-pickering/dhis2-data-munging/master/ous/ous.json>
>>>>> looks like this:
>>>>>
>>>>>
>>>>> {"created":"2016-08-10","organisationUnits":[{"id":"u6yjgvIMzKn",...
>>>>>
>>>>>
>>>>> Hope this helps and best regards,
>>>>>
>>>>> Jason
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Feb 15, 2018 at 6:34 AM, Isaiah Nyabuto <
>>>>> isaiahnyabuto@xxxxxxxxx> wrote:
>>>>>
>>>>>>
>>>>>> Dear Jason and Dhis2 Community,
>>>>>>
>>>>>> I am following your guide on bootstrapping
>>>>>> <https://github.com/jason-p-pickering/dhis2-data-munging/blob/master/bootstrap/bootstrap.Rmd>
>>>>>> dhis2 with R while trying to import metadata using the API.
>>>>>>
>>>>>> I do not understand why my metadata is not imported. Here are my
>>>>>> steps, any help will be appreciated.
>>>>>>
>>>>>>
>>>>>> head(org) name uid code parent shortname
>>>>>> 1 Wikithuki Dispensary Bc371uxfYD5 16925 vpiZlB5cdK7 Wikithuki Dispensary
>>>>>> 2 Gemifa Medical Clinic Z7Lf1n3Fcpi 22907 mEZBjj4fLBT Gemifa
>>>>>> 3 Olympus Medical Clinic NAbQdHuaJFK 22906 PeEcMfBchbr Olympus
>>>>>> 4 Masaba Community Health Unit tYwHeLSnHyb 600616 QR2K4k8VKF1 Masaba CHU
>>>>>> 5 Gatunga Health Centre cmay4WXRmhA 12034 IcAegRcGuV6 Gatunga Health Centre
>>>>>> 6 Cfw Kimangaru Clinic E52UsoBxJVS 11966 vEAFtHnPDrX CFW Kimangaru Clinic
>>>>>> description openingdate closedate comment featuretype coordinates url
>>>>>> 1 NA NA POINT [37.95263,-0.77819]
>>>>>> 2 Clinic NA NA NONE [34.391914,0.059575]
>>>>>> 3 Clinic NA NA NONE [34.3994,0.059575]
>>>>>> 4 Community Unit NA NA NONE [34.46411,0.19358]
>>>>>> 5 NA NA POINT [37.9423,-0.29656]
>>>>>> 6 NA NA POINT [37.53009,-0.54506]
>>>>>> contactperson address email phonenumber
>>>>>> 1 NA NA NA NA
>>>>>> 2 NA NA NA NA
>>>>>> 3 NA NA NA NA
>>>>>> 4 NA NA NA NA
>>>>>> 5 NA NA NA NA
>>>>>> 6 NA NA NA NA
>>>>>>
>>>>>>
>>>>>> I followed the following steps to prepare my df for import.
>>>>>> 1. Removed all the NAs and columns with entire NAs.
>>>>>>
>>>>>> head(new_org) name uid code parent shortname
>>>>>> 1 Wikithuki Dispensary Bc371uxfYD5 16925 vpiZlB5cdK7 Wikithuki Dispensary
>>>>>> 2 Gemifa Medical Clinic Z7Lf1n3Fcpi 22907 mEZBjj4fLBT Gemifa
>>>>>> 3 Olympus Medical Clinic NAbQdHuaJFK 22906 PeEcMfBchbr Olympus
>>>>>> 4 Masaba Community Health Unit tYwHeLSnHyb 600616 QR2K4k8VKF1 Masaba CHU
>>>>>> 5 Gatunga Health Centre cmay4WXRmhA 12034 IcAegRcGuV6 Gatunga Health Centre
>>>>>> 6 Cfw Kimangaru Clinic E52UsoBxJVS 11966 vEAFtHnPDrX CFW Kimangaru Clinic
>>>>>> description comment featuretype coordinates url
>>>>>> 1 POINT [37.95263,-0.77819]
>>>>>> 2 Clinic NONE [34.391914,0.059575]
>>>>>> 3 Clinic NONE [34.3994,0.059575]
>>>>>> 4 Community Unit NONE [34.46411,0.19358]
>>>>>> 5 POINT [37.9423,-0.29656]
>>>>>> 6 POINT [37.53009,-0.54506]
>>>>>>
>>>>>>
>>>>>> 3. Then post the data as follows.
>>>>>>
>>>>>> dest.url <- "http://localhost/dhis/"
>>>>>> url <- paste0(dest.url, "api/metadata?importStrategy=C
>>>>>> REATE&atomicMode=NONE")
>>>>>> r <- POST(url, authenticate(dest.user, dest.pass),
>>>>>> body = toJSON(new_org, auto_unbox = TRUE),
>>>>>> content_type_json())
>>>>>> assertthat::assert_that(r$status_code==200)
>>>>>>
>>>>>> 4. The body looks like.
>>>>>>
>>>>>> jsonlite::toJSON(me, auto_unbox = TRUE)[{"name":"Wikithuki Dispensary","uid":"Bc371uxfYD5","code":"16925","parent":"vpiZlB5cdK7","shortname":"Wikithuki Dispensary","description":"","comment":"","featuretype":"POINT","coordinates":"[37.95263,-0.77819]","url":""},{"name":"Gemifa Medical Clinic","uid":"Z7Lf1n3Fcpi","code":"22907","parent":"mEZBjj4fLBT","shortname":"Gemifa","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.391914,0.059575]","url":""},{"name":"Olympus Medical Clinic","uid":"NAbQdHuaJFK","code":"22906","parent":"PeEcMfBchbr","shortname":"Olympus","description":"Clinic","comment":"","featuretype":"NONE","coordinates":"[34.3994,0.059575]","url":""},{"name":"Masaba Community Health Unit","uid":"tYwHeLSnHyb","code":"600616","parent":"QR2K4k8VKF1","shortname":"Masaba CHU","description":"Community Unit","comment":"","featuretype":"NONE","coordinates":"[34.46411,0.19358]","url":""},{"name":"Gatunga Health Centre","uid":"cmay4WXRmhA","code":"12034","parent":"IcAegRcGuV6","shortname":"Gatunga Health Centre","description":"","comment":"","featuretype":"POINT","coordinates":"[37.9423,-0.29656]","url":""},{"name":"Cfw Kimangaru Clinic","uid":"E52UsoBxJVS","code":"11966","parent":"vEAFtHnPDrX","shortname":"CFW Kimangaru Clinic","description":"","comment":"","featuretype":"POINT","coordinates":"[37.53009,-0.54506]","url":""}]
>>>>>>
>>>>>>
>>>>>> What could be the problem there? I get status 200 and still it
>>>>>> doesn't import.
>>>>>>
>>>>>>
>>>>>> Thank you
>>>>>>
>>>>>>
>>>>>> --
>>>>>> ------------------------------------------------------------
>>>>>> --------------------
>>>>>> Isaiah Nyabuto
>>>>>> +254 729 572 616
>>>>>> Bsc. Health Records Management & Informatics, JKUAT.
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Jason P. Pickering
>>>>> email: jason.p.pickering@xxxxxxxxx
>>>>> tel:+46764147049 <076-414%2070%2049>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> ------------------------------------------------------------
>>>> --------------------
>>>> Isaiah Nyabuto
>>>> +254 729 572 616
>>>> Bsc. Health Records Management & Informatics, JKUAT.
>>>>
>>>
>>>
>>>
>>> --
>>> Jason P. Pickering
>>> email: jason.p.pickering@xxxxxxxxx
>>> tel:+46764147049 <076-414%2070%2049>
>>>
>>
>>
>>
>> --
>> ------------------------------------------------------------
>> --------------------
>> Isaiah Nyabuto
>> +254 729 572 616
>> Bsc. Health Records Management & Informatics, JKUAT.
>>
>
>
>
> --
> Jason P. Pickering
> email: jason.p.pickering@xxxxxxxxx
> tel:+46764147049 <076-414%2070%2049>
>
>
>
--
Jason P. Pickering
email: jason.p.pickering@xxxxxxxxx
tel:+46764147049
Follow ups
References