How to fetch DE and optionset

I am trying to fetch data elements along with their optionset and category.

I use this query

https://play.dhis2.org/2.38.1.1/api/dataElements.json?paging=false&fields=id,name,code,shortName,optionSet[id,name,option],categoryCombo[id,name]

The part I need clarification is this optionSet[id,name,option]. I got back the optionSet id and name. How can I get list of options associated with this option set to be included in the optionset object?

Hi @jetisco4u

You use an API GET request to the options endpoint and filter for the optionset id you want. For example, Instance_URL_Here/api/options?&fields=*&filter=optionSet.id:eq:Option_Set_ID_Here

You could make a change to the request above:
https://play.dhis2.org/2.38.1.1/api/dataElements.json?paging=false&fields=id,name,code,shortName,optionSet[id,name,options],categoryCombo[id,name]
options instead of option

@Gassim thank you. The second example kind of give me a clue. But because of the complication and the deep nested json data I added a data element attribute table write my own sequel query to fetch the data element. I will try to add the options part based on this understanding.

1 Like

Hi Jet,
I think you can do it with your original query… you were missing the s on options.

dataElements.json?fields=id,optionSet[id,name,options[*]]

1 Like