How do I send payload with COC to the api/dataValues endpoint in a custom app


I read in the doc that I can send individual data values as a JSON payload using the following resource using Content-Type: application/json like

    "dataElement": "fbfJHSPpUQD",
    "categoryOptionCombo": "PT59n8BQbqM",
    "period": "202201",
    "orgUnit": "DiszpKrYNg8",
    "value": "10",
    "comment": "OK"

So far this works fine in my custom app. But when I created a data element with category option combination, I run into trouble.

How I send the Payload
I am using a hard-coded token in my local env. But I do comment out the Authorization line when sending in production.

submitToServer = async (row, coc) => {
        const payload = {
			"dataElement": "B4rfhmYXmKk",
			"categoryOptionCombo": "xrfgZqa34U0",
			"period": "WthyJC7lw2W",
			"orgUnit": "MfghrZAzhdw",
			"value": 33,
			"comment": ""
		try {
			await`${dhis2BaseURL}/dataValues`, payload, {
				headers: {
				//  'Authorization': `Basic ${token}`,
				  'Content-Type': 'application/json'
				.then(res => {
						console.log('res.status', res.status)
				.catch(err => {
		} catch (error) {
			te(`There is an error! Please try again.`);

Like I said this work fine except when I am sending this for a dataset with DE with COC.

After I capture the data, I check the datavalue table in the database and the record is there

But when I open the form in Data Entry (Beta) App the form didn’t fetch the filled form.

When I also try to get the data with Data Visualizer App, nothing was returned. However, when I capture the data using the Data Entry (Beta) App, the data replaced the one I have in the database and start showing up in the Data Entry (Beta) App and the Data Visualizer App.

I doubt though if this is related to the custom app. I noticed that another dataset I created with COC work fine.

It is hard for us to tell because your example uses text values in the chart, Serial IDs from the database, and UIDs in the payload. However, it seems like you have the correct understanding so assuming you’re looking at the correct DE/COCs throughout each example, I’d have to guess that you’re not looking in the data capture app correctly – is it the correct OU, Period, and Dataset? Is there a Cat Combo on the dataset that you didn’t specify a value for (attribute option combo AOC)?

I created a metadata with a dataset that uses DE/COCs and it turns out fine even when I capture the data with the custom App. But this particular dataset, while it is saving the data, I cannot access it. In this particular case I am not using the AOC on dataset. I am using the COC with DE. I believe it’s the correct OU and dataset because other DEs in the dataset without COC is coming through.

So I am looking basically for clue as to why this particular dataset does not allow export of data saved with COC to the Data Entry App and the Data Visualizer App.

Okay - well try and reframe your thinking from “why this particular dataset does not allow export of data saved” to “Why can’t I see the data I imported”. That dataset is not going to behave differently than another in terms of how the API works.

Try creating a GET request for the /dataValueSets using the correct period, org unit and dataset and see if you find your Data value for the same DE/COC.

Then also navigate to the data entry app with your browser’s dev tools open to inspect the network requests - use the same dimensions/parameters in the data entry app and then you can compare the network request to the GET request you used to verify your data was entered correctly.

This is more of an exercise to verify and understand what is going on, but it should help guide you with whatever you’re doing.

This one pass. The data was fetched

Also this one too pass. To the right of the screenshot you can see the same data as the api request. But to the left where they are supposed to appear in the Data Entry App, they aren’t appearing.

I don’t know what to make of this. Everything seems ok but it’s not working. I have cleared cache and site data.

Indeed that does seem strange. Can you confirm the same behavior with the legacy/original data entry app?

Yes I checked with the legacy App and it’s more or less the same. I saw that data was fetched but it is empty in the form. If I use it to save the data, it will also save properly.

More or less the same as the new app (which is faulty) or the same as the the POST request you’re using to submit the data?

1 Like