I had some questions about API requests and asked other developers in the Developers Workspace for support. I got some good responses; therefore, I thought it’d be helpful to have a wiki with helpful questions & responses that the developers in the DHIS2 Community of Practice can contribute to. Thanks!
This is a wiki post which means all community members are welcome to edit it, add a Q&A or helpful tips then tag their CoP usernames at the end of this post. See contributors list at the end of this post.
@RModi I would suggest to use two different queries and concatenate the result. Might be less daunting.
@tzemp You might be able to structure a single query using nested references … but if you want to access completely different resources from the api (say messageConversations and dataElementOperands) you’d probably need to make multiple requests
@tzemp to structure a single query using nested references, e.g. if you want to see the names of categoryOptions associated with a given program, you could use [instanceURL]/api/programs?fields=id,name,categoryCombo[id,name,categories[id,name,categoryOptions[id,name]]]
@tzemp you can put the filters at the end, like: [instanceURL]/2.37.2/api/programs?fields=id,name,categoryCombo[id,name,categories[id,name,categoryOptions[id,name]]]&filter=categoryCombo.categories.name:like:Implementing
@tzemp you’ll need to do concatenate the filter conditions with
@tzemp you can specify a rootJunction if you don’t want to use AND, e.g. &filter=object:like:something&filter=object2:eq:xyz&rootJunction=OR
See Logical Operators section here:
@austin In general a deprecated api is set to be removed in a future version, so relying on it isn’t recommended.
@austin you can specify explicit fields within the api end point so you shouldn’t need
fields=* (which can create a heavy request)
Maybe you can reuse these example API calls
@Gassim Generally, to get an ID of a metadata object, you need to check its API endpoint, here are two important resources that will help you find your way through the API:
- /api/schemas - For example, InstanceURL/api/schemas
** See Schemas docs
- /api/resources - For example, InstanceURL/api/resources
** See Resources (the Web API entry point) docs
After that you will request the ID from the end point and use fields and filters to return the required result.
Q - How do I get all sublevels of a specific org unit - using [nested objects]
If you want to list out a nested object you need to add a
children field in square brackets along with the fields you want to retrieve. Nest the
children field as deep as your maximum Org unit level is. The example below fetches the four sub-levels of the org unit with the Id