I want to export the HIV aggregated data from DHIS2 to our database for external analysis. This needs to be implemented using web APIs.
I am doing it in JAVA using the DHIS2 JAVA client.
Right now I am able to make the connection and list all the organizations.
But the part where I want to fetch the data is not working.
In the documentation it is mentioned I have to pass the datasetId. From where I will get the datasetId.
Either it is possible through Java client or not?
Any sort of help and guidance will be highly appreciated.
Thank you for your question, and welcome to the community!
Generally, to get an ID of a metadata object, you need to check its API endpoint, here are two important resources that will help you find your way through the API:
As for your situation, you’d need to get the dataSetId from the /api/dataSetID endpoint. Here’s an example where I specify the required fields to be dataSetId and dataSet name but I filter the results to only show the dataSetIds for a specific organisation unit:
[the instance URL]/api/dataSets?fields=[the fields to return]&filter=organisationUnits.id:eq:[the organisation unit ID]
Thanks and I hope this helps!
Thank you for your answer. Lemme check this out.
Great, thanks! Let me know if it solves the issue and feel free to post back to the community with more questions or about your experience / use case.
@Gassim thanks for your guide. The link you mentioned is working for me. I just want to ask whether there is some DHIS2 Java Client to handle this request or I need to call it by using Java HTTP Client.
You’re welcome! If I understand your question properly then yes, if your Java client works as an API and can authenticate between itself and the instance then it should be okay to use it to connect to the DHIS2 API endpoints.
Working on a similar task too, retrieving the data via API for analysis using R
That’s really cool @Mbevi! Thanks for sharing! Please feel free to make a topic about your experience on retrieving data from DHIS2 API using R. Other developers in the #development category will probably find it helpful too. Even if you share notes like why you chose R and what are the other options, what are the inputs/outcomes?
Good luck! And for sure post back if you need any support from the community👍