How to retrieve "Report Date" data element together with numeric indicators via R API?

Greetings from LEBANON!

I am trying to automate my weekly reports in R using the DHIS2 API.

  • I have several numeric data elements that I can successfully retrieve using /analytics.json
  • I also have a date data element (SbvKLWn19mW, called “Report Date”) that I want to include in the same dataset.

Problem:

  • When I add the report date data element to the analytics URL, I get this error:
    Data elements must be of a value and aggregation type that allow aggregation: [SbvKLWn19mW]

I want a single R script that pulls numeric indicators + report date automatically from the DHIS2 server, without manually exporting JSON files.

Is there a DHIS2 API endpoint that supports mixed types (numeric + date) in one call?

Highly appreciated,

Hi @HawraaSweidan

Thank you for your post. To begin with as you have noted, the api/analytics doesn’t mix date type (non-aggregated) with aggregated numeric data elements.

You might need to send multiple API requests in R (one to the analytics endpoint to retrieve the aggregated values, and another for the ‘report dates’) then merge the result:

  • /api/dataValueSets for the ‘report date’
  • api/analytics for the numeric data elements (that you are already retrieving)

I’m not sure there is one at this point. You could purpose this as an idea to the software roadmap, see ideas!

Thanks!

Hi @HawraaSweidan ,

You can also use this trick for downloading numeric and date type data elements from the same Data Visualiser pivot table – the API query called be called from R.