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?
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.
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)?
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.
Follow up to your response here about using the fields parameter to query particular data,
According to the documentation, I can query a field by its attribute ID and it would give me the value
" Example: Get id, name and the value of a user defined attribute with ID DnrLSdo4hMl for organisation units:
/api/organisationUnits?fields=id,name,DnrLSdo4hMl
The attribute is then included as property DnrLSdo4hMl of each matching object in the response. This can be renamed using the rename transformer as shown in the next section."
Following this, I have tried to build my query with the attribute IDs I’m interested in for the attributes of the TEI, and I am not receiving the desired response
@lillian1n2 The fields parameter returns the parameters you want in the JSON query.
For the case of querying a specific attribute(not value though), you can use the filter with the metadata filter operators
Could you give me an example? What fields of the attributes array would it return without the value? I’m still getting a handle on the filter parameter when used with the TEI attributes.
Supposed you wanted to get storedBy, displayName attributes only,
you run a query like this http://xxxx/api/trackedEntityInstances?trackedEntityType=QZnlVF9iSlD&ou=yM3rUZC0Hvl&fields=trackedEntityInstance,attributes[storedBy, displayName]
And if you want to get only a specific attribute value like displayName=“Account No” or storedBy=“some user”, you would do this; filter the attribute using operators like EQ, LIKE, etc for example attribute=idOfTheTEIAttribute:EQ:theValueToFilter as shown in http://xxxx/api/trackedEntityInstances?trackedEntityType=QZnlVF9iSlD&ou=yM3rUZC0Hvl&fields=trackedEntityInstance&attribute=osf4j0yRYlm:EQ:accountNO assuming osf4j0yRYlm is the TEI attribute id for accountNo and other values.
As for the first example, I was able to isolate the field names and that responds as I would want from my end.
As for the second example, this involves querying the attribute parameter which I discovered does not respond as desired. I raised the issue on jira.
So my main issue, is how to select certain attributes, I am not interested in all of them, but specific ones. So I could use the field parameters (and I have) but I only want for 4 out of 6 of the attributes because it’s affecting how I’m building my code for parsing through the response array in JSON.
I thought the attribute query would work, but it isn’t responding as I need it to. With fields, it slims down the response to the fields I am interested in, however, I still need to find out how to select specific attributes of the list.
@Gassim Question: After raising the issue on jira, what can I expect after for resolution of the issue? Especially also considering I am doing the development on 2.37.7.1 for which I don’t know whether there will be further patches/updates.