Fetch data for multiple data elements in aggregated model using Web API

hi

I want to ask if I want to fetch multiple data elements data from single data set having the same category combo, what should I do? DHIS2 web API won’t allow me to fetch data for data elements how i can do this any guide?

api/dataValues?de=LWw5uN&co=aRVOZf&ou=GizpHuJ&pe=20221023

this is what I am doing but it fetches for only a single data element. I want to fetch 5-10 data elements simultaneously.

Hi @Tooba
Welcome back to the community! :tada:

The api/dataValues endpoint is used only for individual data values; however, you can use the api/dataValueSets to fetch multiple values from the same dataset.

More details about Reading data values (you can either use a data set or a data element group) Data - DHIS2 Documentation

Thank you @Gassim yes I have read the documentation and I have used it to fetch the data for the complete dataset. But now the aim is to fetch 5 data elements data for 100 HF which entered that data on daily basis. here fetching the whole dataset is not may be very resource full.

Is there any way to fetch 5-6 data elements in the single call ?

1 Like

You can use their ID in the dataElement parameter. The dataElement can be used more than once.

Hope this one works! :slight_smile::+1:

yes i did but generate error

Please share the error, thanks!

webMessage xmlns=“http://dhis2.org/schema/dxf/2.0” httpStatus=“Conflict” httpStatusCode=“409” status=“ERROR” errorCode=“E1100”

Data element not found or not accessible: L---5fsMdjuN;O---hCUuFt

Could you share the full API request? Are the data elements listed like this: ‘dataElement=L—5fsMdjuN;O—hCUuFt’ OR ‘dataElement=L—5fsMdjuN&dataElement=O—hCUuFt’

Thanks!

/api/dataValues?de=LWw5fsMdjuN&co=aRBeL3hVOZf&ou=GizG3CJpHuJ&pe=20221023

But there is only one dataElement mentioned? The error shows: ‘;O—hCUuFt’ where did that come from?


Please check that you have the required access rights to the data element? That the categoryCombo is the same ID as well:
/api/dataElements/LWw5fsMdjuN?fields=id,name,sharing,categoryCombo

@Gassim
api/dataValues.json?de=sdkSVROyT1I;20OhCUuFtRYRW&co=aRBeL3hVOZ&ou=GizG3CJpHuJ&pe=20221023

This is the thing I want to pass multiple data elements but their Cat Combo is same

Please try this request instead (dataElement can be repeated more than once):

api/dataValues.json?de=sdkSVROyT1I&de=20OhCUuFtRYRW&co=aRBeL3hVOZ&ou=GizG3CJpHuJ&pe=20221023

httpStatus": “Conflict”,
“httpStatusCode”: 409,
“status”: “ERROR”,
“message”: “Data element not found or not accessible: sdkSVROyT1I,OhCUuFtRYRW20”,
“errorCode”: “E1100”

Are you able to access:
/api/dataElements/sdkSVROyT1I?fields=id,name,sharing,categoryCombo

/api/dataElements/OhCUuFtRYRW20?fields=id,name,sharing,categoryCombo

Please check the sharing settings are correct.


You might also want to clear application cache using the Data Administration app → Maintenance

Yes I am able to access both

Interesting! We need to check out the reason. Is this happening for any data element you use or only just for these two?

BTW,

Are you sure this is a correct ID? System generated ID values must not start with a number.

yes its typo error i am passing the correct one OhCUuFtRYRW
and yes this happen for all . as far as I am passing single data elements results were fetched but when I pass multiple I got errors

Please what version of dhis2 are you using? Would you be able to test this on play.dhis2.org and report back if you are facing the same issue?

Thank you!

ok let me check

@Gassim

ttpStatus": “Conflict”,
“httpStatusCode”: 409,
“status”: “ERROR”,
“message”: “Data element not found or not accessible: s46m5MS0hxu,UOlfIjgN8X6co=Prlt0C1RF0s”,
“errorCode”: “E1100”

@Gassim will you please guide me here what to do next

1 Like

@Tooba am also looking for the same solution of pulling multiple data elements data using API. i struggled

1 Like