Accessing DHIS2 trackedEntityInstances through the api endpoint does not return all attributes

Hello,
Accessing DHIS2 trackedEntityInstances through the api endpoint does not return all attributes.
By default when you access the tracked entity instance for the first time, it returns only two attributes, fisrtName and Last Name.

When you edit the entity it now add the Unique ID, but still does not return gender.

When you change the gender, it does not show up when you call the endpoint.
But still is displayed on the UI

When you change the gender, it bring and error in the console saying.
Error: Failed to execute ‘get’ on ‘IDBObjectStore’: No key or key range specified.
Even you create new Instance, the gender attribute is not being returned even when you selected gender.
It looks like all attributes with drop downs are not returned through the api.
I used both the 2.30 and 2.31 demo servers.
I need to be able to return all attributes.


Thanks

1 Like

A post was split to a new topic: How to Create Tabular Data Entry Form

Hey @carapai!
You are right that the endpoint will by default only return a limited set of tracked entity attributes. The attributes returned will be dependent on which attributes that is set to “display in list”. When asking for tracked entity instances in the context of a program, the programs tracked entity attribute settings is used. When asking in the context of a tracked entity type, the tracked entity attributes that is set in the tracked entity type will be used.
If the user has access to capture data in the organisation unit that owns the tracked entity instance, the endpoint also allows querying the other attributes that are not returned by default. This is done by adding url params:

attribute=(uid of attribute)

For adding several attributes:

attribute=(uid of attribute)&attribute=(uid of attribute)

The tracker app however should take care of all this - I was not able to reproduce the problem that is demonstrated by your screenshot. Can you make sure you clean the cache and retry - if the problem persists it would be great with some steps to reproduce it.

Best regards, Markus

1 Like

Hello @Markus,

I am using these endpoints, how can I add the attribute=(uid of attribute)

https://play.dhis2.org/2.31.0/api/trackedEntityInstances/vOxUH373fy5
https://play.dhis2.org/2.30/api/trackedEntityInstances/vOxUH373fy5

For all those endpoint the gender is not returned

but for 2.29 the gender is returned

https://play.dhis2.org/2.29/api/trackedEntityInstances/vOxUH373fy5

I have tried https://play.dhis2.org/2.31.0/api/trackedEntityInstances/vOxUH373fy5?attribute= cejWyOfXge6

But still returns the same result

Hey again, when including a specific tracked entity instance id in your route, the parameter is not supported:
https://play.dhis2.org/2.31.0/api/trackedEntityInstances/vOxUH373fy5?attribute=cejWyOfXge6

If however you pass the tracked entity instance as a url parameter it will work:
https://play.dhis2.org/2.31.0/api/trackedEntityInstances?trackedEntityInstance=vOxUH373fy5&attribute=cejWyOfXge6

Markus

1 Like

Thanks @Markus,
However if I don’t know the uid of tracked entity Instances, I will not be able get all attributes.
And again passing or not passing the attribute will not affect the result, all attributes will be returned as I needed.
But now I want to filter tracked entity by attribute and return all attributes
For example this returns me what I need, I knew the tracked entity instance uid
https://play.dhis2.org/2.31.0/api/trackedEntityInstances?trackedEntityInstance=PoytmgwvU4a
However for the same entity only knew the firstName so filtered using firstName
https://play.dhis2.org/2.31.0/api/trackedEntityInstances?filter=w75KJ2mc4zz:eq:sxz&ouMode=ALL
No gender was returned.

Charles

1 Like

Thank you so much @Markus . This saved me a lot. I spent hours, trying to see what’s going wrong, but finally hit this hint. Worked for me :+1: DHIS2 2.35

Best,
Josue

2 Likes