How to import event `dataValues` using option IDs (and not string values)?

I am trying to create events linked to trackedEntityInstances via the API.

The below payload works great when I send a POST request to /api/33/events. However, when mapping related dataValues, I’m finding that I have to use the string value for the option value (e.g., acute_abdomen) instead of this option’s UID (Z3a44uyRxNB). For my specific use case, this might be problematic down the line as many teams might be copying this dhis2 configuration and localizing it to their context… we fear the option values might change, but we can count on the option UIDs to be consistent across locations and languages. Therefore, is there a way to import dataValues via the API using the option value Ids instead of string values?

This below payload works well and the corresponding option value label Acute abdomen displays correctly to the user on the front end (in both english and french).

{
            "program": "uGHvY5HFoLG",
            "orgUnit": "l22DQq4iV3G",
            "programStage": "hfKSeo6nZK0",
            "trackedEntityInstance": "cPQDZSzEuiu",
            "eventDate": "2023-07-26T00:00:00.000",
            "dataValues": [
                {
                    "dataElement": "ZTSBtZKc8Ff",
                    "value": "acute_abdomen" //here we send the option coded string value
                }
            ]
}

This next payload does not work when I send the option Id Z3a44uyRxNB as the value… is there any attribute I can add to this payload (e.g., optionSetId?) in order to use option Ids instead of the string values?

{
            "program": "uGHvY5HFoLG",
            "orgUnit": "l22DQq4iV3G",
            "programStage": "hfKSeo6nZK0",
            "trackedEntityInstance": "cPQDZSzEuiu",
            "eventDate": "2023-07-26T00:00:00.000",
            "dataValues": [
                {
                    "dataElement": "ZTSBtZKc8Ff",
                    "value": "Z3a44uyRxNB" //using the option Id instead of string value
                }
            ]
}
3 Likes

Hi @aleksa_krolls

Thank you for your post and welcome back to the community. I was hoping to get an expert response before I make any speculation, but I hope my input would be helpful.

I’m reading in the documentation that program rule variables have some sort of similar functionality to the one you are describing i.e.:

useCodeFor- OptionSet If checked, the variable will be populated with the code - not the name - from any linked option set. Default is unchecked, meaning that the name of the option is populated. (source)

I’m wondering if it is possible to use code instead of value? It’d be great if you have time to test it. The code then would be a default code for all (similar to the UID).

There might be another way to fix this issue before sending API requests? For instance, a default template sheet where this one column that will change because of localizing can be modified and then exported as CSV?