Including data element empty values when using analytics web API resource

Hello DHIS2 community,

My colleague @Modo and I have recently been working with the analytics resource in the web API, trying to pull monthly values for a given data element for the past year (for defined series of organization units) in CSV format. However, we found that the response excludes empty values. We’ve tried including these using the hideEmptyRows and hideEmptyColumns query parameters, but these probably only apply to table layouts. Is there a way to include empty values in the response?

For reference, this is the format of our URL: /api/analytics.csv?dimension=dx:UVgMoeAZhnM&dimension=ou:NUnVKR3k7G9;LEVEL-4;OU_GROUP-Zh1inFu0Z2O&dimension=pe:MONTHS_LAST_YEAR

Hi @rfromthecastle

Welcome to the community!

May I ask what type of data element is it and why is it important to return ‘empty values?’

From your explanation it seems that you’d want to list where the data set is and in which year whether or not it’s has values? The empty values would be for all the datasets and OUs in the specific period that are not returned by the API request

Hi Gassim, many thanks for your response, We are now trying to build the dashboard outside the DHIS2 (Having difficulty creating our own indicator or data element, long time approval from the Gov ) so all the data is needed even if it’s showing empty. Any suggestion from you to edit the empty value to zero and be able to pull it out by using API?

@Modo welcome to the community!

Please feel free to create a topic with description of the challenge that is being faced and the use case. We could get further advice from other community members and the software team. It might also lead to a feature request which will make it available for use at ease.

I’m not sure how the API responses are being processed after pulling out the data but I think the easiest approach would be to have the space for all the values and then populate the fields, the fields that don’t get populated are the empty values that didn’t get pulled from the API.

However, this requires that the the fields are already known but that doesn’t seem the case, right? So in this case my suggestion is to use the /sqlViews endpoint rather than the /analytics endpoint. Have you tried using SQL View in the Maintenance app?

Finally, if nothing else works, it might be recommended against, but you might be able to pull the data directly from the database. :+1: