dataSetValues API endpoint unable to save form data with attributes/catgeoryOption/comboOptions?

Hi All,

My name is Daniel Adenew, I m lead software engineer. The problem i m showing you today is helpfull plus tricky for future advancement of DHIS2.

I have the following form format:

And , I m sending data through api using the following code:

var jsonData = {
“dataSet”: “Ow7CNQwgZm3”,
“completeDate”: “2020-06-18”,
“period”: “2020Q1”,
“orgUnit”: “EENDe38Diwq”,
“categoryOptionCombo”:“HllvX50cXC0”,
“attributeOptionCombo”:“BZ0XwmqYzQm”,
“dataValues”: [
{ “dataElement”: “v5IRd4L2b9G”, “value”: “55”,“comment”: “NodejsCode” },
]
}

API URL to endpoint: http:/xvy:7878/api/29/dataValueSets

and when i run the code it shows me the following error which i didnt know:

I m trying to save data for instance:

OrgUnit:1
Peroid:2020Q1
Visit: 1visit

Please ,help me patch this quick fix i will share a complete solution to integrate DHIS2 with any third party app.

Hi Daniel,

The error you got explains it well, we believe. The attributeOptionCombo you passed - BZ0XwmqYzQm - either does not exist or the user, you are trying to save data with, does not have data write authority.

You need to check two things:

  • make sure the attribute option combo is a valid one and
  • make sure your user has its sharing setting properly configured for all the options under the mentioned attributeOptionCombo

One thing striking from your screenshot is you have visits, can you tell more about your usecase? Do you think the aggregate side of DHIS2 is a best fit? Have you considered using DHIS2 tracker modules?

Thank you,
Abyot.

1 Like

HI Abyot ,

Thankyou for your constructive feedbacks and time.

Yes, I owe you a brief explanation.

Abyot , this are the step I followed to save a dataSetValues into a given dataset. The whole idea for doing this is submitting a complete data entry using API.

For example in my case Laboratory Checklist Forms as we see on data entry form below screen.

We have visits that could run 1-5 and i modeled that as visits on datasets category combination option and visits is set as attribute and its perfectly working. That was what I need, 5 different dimension of data element values.

Now, I have this ODK application with detailed and large forms on it, which some of them are not even able (my experience) not able to be developed as they are in DHIS2. So due to time and resource the best fit is to model them using ODK and submit data necessary for visualization/scoring into DHIS2 per visits dimension.

Thus, to work with the API I used the following endpoint which i believe handy in my situation.

http://197.156.76.44:8080/api/dataValueSets

As per the documentation of DHIS2 API here ;Home - DHIS2 Documentation

I have used the following JSON style:

{
  "dataSet": "dataSetID",
  "completeDate": "date",
  "period": "period",
  "orgUnit": "orgUnitID",
  "attributeOptionCombo": "aocID",
  "dataValues": [
    {
      "dataElement": "dataElementID", 
      "categoryOptionCombo": "cocID", 
      "value": "1", 
      "comment": "comment1"
    },
    {
      "dataElement": "dataElementID", 
      "categoryOptionCombo": "cocID", 
      "value": "2", 
      "comment": "comment2"
    },
    {
      "dataElement": "dataElementID", 
      "categoryOptionCombo": "cocID", 
      "value": "3", 
      "comment": "comment3"
    }
  ]
}

I have used the following API working inspection on my broweser to find out codes for AttributeOption,ComboOptions…etc as shown below

When i manually enter data DHIS2 calls the
e.g dataValues end point and send the attribute options as the following code , which i have used the same code in my API integration applicaiton.

de:v5IRd4L2b9G
co:HllvX50cXC0
ds:Ow7CNQwgZm3
ou:EENDe38Diwq
pe:2020Q1
value:2
cc:MyTZiEZdtsx
cp:SRFu8JYasHM <== I presume this the attribute options that i have used.

I have used below inspection to identify their UID’s for attributes ? DHIS2 API uses it internally?

I have checked that by inspecting the source of attributOptionCombo box on dataset as follows:

image

Then I have formulated my code as follows: my json to test a single data save from my API to DHIS2 through the API endpoint mentioned above.

{
“dataSet”: “Ow7CNQwgZm3”,
“completeDate”: “2020-06-18”,
“period”: “2020Q1”,
“orgUnit”: “OTJusq4oEbn”,
“categoryOptionCombo”: “HllvX50cXC0”,
“attributeOptionCombo”: “SRFu8JYasHM”
“dataValues”: [
{ “dataElement”: “v5IRd4L2b9G”, “value”: “55”,“categoryOptionCombo”:“HllvX50cXC0”,“comment”: “DanielAdenew Commeted on this” },
]
}

And DHIS2 shows :

// 20200624035703
// http://localhost:3000/labchecklist

{
“responseType”: “ImportSummary”,
“status”: “SUCCESS”,
“importOptions”: {
“idSchemes”: {

},
"dryRun": false,
"async": false,
"importStrategy": "CREATE_AND_UPDATE",
"mergeMode": "REPLACE",
"reportMode": "FULL",
"skipExistingCheck": false,
"sharing": false,
"skipNotifications": false,
"datasetAllowsPeriods": false,
"strictPeriods": false,
"strictDataElements": false,
"strictCategoryOptionCombos": false,
"strictAttributeOptionCombos": false,
"strictOrganisationUnits": false,
"requireCategoryOptionCombo": false,
"requireAttributeOptionCombo": false,
"skipPatternValidation": false,
"ignoreEmptyCollection": false,
"force": false

},
“description”: “Import process completed successfully”,
“importCount”: {
“imported”: 0,
“updated”: 1,
“ignored”: 0,
“deleted”: 0
},
“dataSetComplete”: “2020-06-18”
}

and some time it does even show me the following error message , as attribue i m using is not found.
I have run psql update incase anything for the AttributeOptions.

// 20200624043928
// http://localhost:3000/labchecklist

{
“responseType”: “ImportSummary”,
“status”: “WARNING”,
“importOptions”: {
“idSchemes”: {

},
"dryRun": false,
"async": false,
"importStrategy": "CREATE_AND_UPDATE",
"mergeMode": "REPLACE",
"reportMode": "FULL",
"skipExistingCheck": false,
"sharing": false,
"skipNotifications": false,
"datasetAllowsPeriods": false,
"strictPeriods": false,
"strictDataElements": false,
"strictCategoryOptionCombos": false,
"strictAttributeOptionCombos": false,
"strictOrganisationUnits": false,
"requireCategoryOptionCombo": false,
"requireAttributeOptionCombo": false,
"skipPatternValidation": false,
"ignoreEmptyCollection": false,
"force": false

},
“description”: “Import process completed successfully”,
“importCount”: {
“imported”: 0,
“updated”: 0,
“ignored”: 1,
“deleted”: 0
},
“conflicts”: [
{
“object”: “SRFu8JYasHM”,
“value”: “Attribute option combo not found or not accessible for writing data”
}
],
“dataSetComplete”: “2020-06-24”

and , when i checked on actual data-entery form values are not still shown .

Trackers:

I am much experienced with manipulation of Data Entry forms. I am new to Tracker concept and Didn’t know How I Can achieve similar outcomes using Trackers ?. If you send some links/examples to review I would appreciate it.

Summery of my Question:

  1. Does this have related impact with my version of DHIS2 being 2.30.1

  2. Why the internal API codes for AttributeOption UID’s i presume doesn’t work from, while i followed
    the same style with DHIS2 API works like i showed to you above when DHIS2 send data Values per attribute Options ?

  3. What else method should i look through to save bulk data Sets , if there is any other end point to do this job ?

Thank you very much!

Daniel Adenew

Hi Daniel,

This behavior of importing dataset values is not related to your DHIS2 version. Since You have 2.30.x everything should work fine. I have also experimented the same problem using this method so I decided to use ADX data format. Since it is standardized and well documented I was able to push data with this method.
here is the link: Home - DHIS2 Documentation.
However I will advice to use in the http request dataElementIdScheme=UID&orgUnitIdScheme=UID and of course will use UID in the adx payload instead of the code.

I hope this may help.
Thanks

1 Like

Hi @dannyboy
Did you find a solution to this?
I am experiencing the same issue while trying to post to the api endpoint.

HI All,
I found the solution,
The attribute option combination UUID is hidden and isn’t visible by inspecting the elements on the browser. I was inspecting and later found out that the id shown isn’t identifying the attribute option combination.
So to find out the exact attribute option combination, go to maintenance-> category> category option combination and search from your category option i.e the one categorized in the category with attribute data dimension

2 Likes

Hello,

What about this error? Is there something I am missing? I can’t quite tell why the import fails.

Hi @lillian1n2

Would you please create a post describing the whole issue or add more details and description to your post? It might not be clear yet how relevant it is to this topic post.

Thanks!

Hey @Gassim,

I am also having trouble importing values into the dataValueSet API endpoint. When simulating the request on Postman, that is the error that I get.

It might not relate to the error on the on the attributeCombo but I was hoping for assistance on the general error posed.