Retrieving OU that include the parent field via api

Hi team,
I am trying to retrieve the id, name, level, shortname and parent fields of an organisational unit via api using the following call https://staging.testserver.org/dhis2/api/organisationUnits/EQKHILXi6xI.csv?paging=false&fields=id,code,level,name,shortName,parent&includeDescendants=true.

But the result I am getting does not include the parent field in the exported csv. See the result I am getting below:

I want an extra column which show the parent id of the OUs.
@Gassim @Quoda
Thanks!!

Hi @arnold

Yes, you are right, it seems that the .CSV doesn’t include these arrays (parent is an array) in the columns. I had @jason assist me with this and his suggestion implies using an Import/Export app or converting the JSON to CSV.

Another way to approach this is to use the SQL View and create the SQL with the result you want then extract the query result using the API (if you need to use the API).

Another idea is maybe to use other fields which do appear in the CSV download such as path or ancestor?

Thanks!

Hi @Gassim
Thank you for providing various alternatives to my problem. I have used the the method to convert the JSON to CSV and that solved my problem.

Many thanks!!

1 Like

You’re welcome @arnold!

This suggestion is from @jason :wink: Mine were the other options :grin::pray:

1 Like