I have been going through the documentation for reading data values using the API here: Data - DHIS2 Documentation
Here is an example query to get the values for a dataElementGroup for an organsation:
This returns a
lastUpdated field. BUT, I am not sure if this is when the entry was first created or just when it was lastUpdated? Are these two different things?
For example, I want to get all newly added data in the last month - this will include data values for the actual last month, but also a lot of values that have been entered in the last month, but for previous months.
Additionally, is it possible to do the above query at the orgUnit level rather than specifying a specific orgUnit?
To your first question regarding createdAt and lastUpdated:
createdAt is set only the first time the value is recorded in the system, while lastUpdated is set to the current time each time you change the value. This means in cases where data is changed after initially being added, the timestamps will be different.
If you want a collection of any values added OR changed the last month, you should be using lastUpdated, while if you are only after newly added data, createdAt would be the way to go.
There’s no parameters that would help you retrieve data for a specific org unit level in this API, but if it’s a requirement for your usecase, I would suggest writing a issue for the new feature in Jira and see if it’s something that could be added to the API
Do you know how I can specify in a query to reference the createdAt field and retrieve it? At the moment, taking my example API query above, I have only been able to use lastUpdated, a period or else a startDate and endDate. But, startDate and endDate filter on the period and not on when the entry was created.
Ideally, I would want to replace the lastUpdated with createdAt in this example query:
But, then I get an error saying one of the other time frames must be specified.
“At least one valid period, start/end dates, last updated or last updated duration must be specified”
Thanks for the tip about requesting a new feature - I will do this in Jira!
just had a quick look at the code now, and I see createdAt is actually not supported at the moment as a filter. I think that would be another useful feature you can propose in Jira. In other words, currently theres no way to solve this specific usecase using the API.
Aha, I see thanks so much for your quick responses.