Web-api to get all sublevels of a specific org unit not working 100%

Hi all,

We have used the following web APi but it does not return all sublevels of an org unit.
e,g
https://URL/api/29/organisationUnits/IeWV4MnC6YR.xml?fields=name,id,children[name,id,children[name,id]]

The above API gives us only levels 1,2 and 3 from the picture below, but we want all 4 levels
image

The parent of levels 2,3 and 4 is Ancuabe (level 1)- we have used the ID of ANCUABE in the API.

How can we solve this?

Thanks

Hi @hernandezmachava

If you want to only list out the orgUnits in the fourth level, you can use the level parameter and the path filter to make sure it is the under the specified orgUnit. Replace ImspTQPwCqd with Id of Ancuabe in your case.

https://play.dhis2.org/40.0.1/api/40/organisationUnits/?level=4&fields=id,name,path,level&filter=path:like:ImspTQPwCqd

Or, If you want to list out a nested object you need to add a third children field so

https://play.dhis2.org/40.0.1/api/40/organisationUnits/ImspTQPwCqd?fields=name,id,children[name,id,children[name,id,children[name,id]]]

2 Likes

Hi @redet,

A nested object is what I wanted. Thank you so much for the solution.

2 Likes

Good, idea! Would you like to add this point to the API wiki post: developers, collaborate here with API Q&As & tips you find helpful for other developers

Thanks!

1 Like

Sure, Done!

1 Like