trackedEntityInstances endpoint GET request

Hello, I’m building a custom app for my organization to help interact with some DHIS2 data.

I would like help in identifying how to slim down the .json response fields when putting in a GET request to only those which I need. I actually only need specific attributes to the TEI so what do I need in include to only have that which I’d like?


(This is dummy data, not sensitive info) This is the response I get when making a call with this …

http://url/api/trackedEntityInstances.json?program=kpauVkGAK8z&ou=yM3rUZC0Hvl

I’m only interested in the attributes, and not all attributes, 3 out of the 5. What do I need to add to my api call?

Also, making the same request with the new tracker endpoint, and using attribute parameter in the call to specify the attributes, returns more or less the same response with the fields I’m looking to get rid of in the response.

http://xxxx/api/tracker/trackedEntities?trackedEntityType=QZnlVF9iSlD&orgUnit=yM3rUZC0Hvl&attribute=osf4j0yRYlm&attribute=p1NB7CSm10L

What am I not getting right?

1 Like

Hi @lillian1n2,

Good luck with your custom application! Please try the fields parameter. For example, https://play.dhis2.org/2.35.14/api/trackedEntityInstances?ou=ImspTQPwCqd&progam=IpHINAT79UW&fields=attributes[displayName,value]

Field parameter will allow you to select the attributes that you want to appear in the response, read more here: https://docs.dhis2.org/en/develop/using-the-api/dhis-core-version-master/metadata.html#webapi_metadata_field_filter


If you want a good review, in this video @austin explains queries and how to use the filter and fields. Web App Development Workshop - Day 2 - Queries and mutations - YouTube

If you haven’t you might be interested in checking out the latest 2022 DHIS2 Web App Development Academy playlist: https://youtube.com/playlist?list=PLo6Seh-066RzKN1UE_53LLEnhtPmy6zRc

1 Like

Hi @lillian1n2,

Sorry my previous post didn’t touch the point exactly. The request and your use of the attribute parameter is correct but since it’s not returning the expected result it might be a bug, so would you like to create a jira bug issue (in jira.dhis2.org)?

Thanks!

2 Likes

Thank you for the response. I will endeavor to raise the issue.

Also thank you for pointing me to the webinars on app development and I had actually had a look at those resources when preparing to undertake the project. They helped with my understanding of how to work with the API.

Though the resources that were more specific to the work I’m trying to do with the app is this:
https://dhis2trainingland.com/eportal/?tutorial=linking-dhis2-to-an-external-web-portal-using-php-mysql

Because it’s giving me ideas of how to have my code interact with the data retrieved via API.

1 Like