eventChart update via api

Hi Folks,

I have an eventChart that I have saved as a favorite and added to my dashboard.

The chart uses a daily period that I would like to update each night so that the chart always showing the current (today’s) data.

I’m using a python script to get the current chart’s json (/api/eventCharts/QkBhkdqb8FU.json?fields=:owner), I then update the period value and upload (with a ‘put’ request) the updated json payload back via (/api/eventCharts/QkBhkdqb8FU.json)

The payload I put seems to have the correct data and structure, the put request response and content looks good:

<Response [200]>

{“httpStatus”:“OK”,“httpStatusCode”:200,“status”:“OK”,“response”:{“responseType”

:“ObjectReport”,“uid”:“QkBhkdqb8FU”,“klass”:"org.hisp.dhis.eventchart.EventChart

"}}

When I refresh the “/api/eventCharts/QkBhkdqb8FU.json?fields=:owner” link many of the necessary fields to define the chart selections seem to have been overwritten or the values lost.

I tried to use the request.paste() function in python but I get the following error:

<Response [500]>
{“httpStatus”:“Internal Server Error”,“httpStatusCode”:500,“status”:“ERROR”,“message”:“object references an unsaved transient instance - save the transient instance before flushing: org.hisp.dhis.program.Program”}

Below is the JSON from the original get, then the updated payload that I ‘put’ and finally what the server shows after the put.

Original: (periods is set to “20170130”

{“lastUpdated”:“2017-01-31T15:32:25.206”,“id”:“QkBhkdqb8FU”,“created”:“2017-01-31T15:32:25.206”,“name”:“MLC Family Planning Months of Stock on Hand”,“showData”:true,“baseLineValue”:6.0,“publicAccess”:“rw------”,“userOrganisationUnitChildren”:false,“type”:“BAR”,“hideEmptyRows”:false,“userOrganisationUnit”:false,“hideNaData”:false,“regressionType”:“NONE”,“completedOnly”:false,“sortOrder”:1,“collapseDataDimensions”:false,“aggregationType”:“SUM”,“userOrganisationUnitGrandChildren”:false,“hideSubtitle”:false,“outputType”:“EVENT”,“hideLegend”:false,“externalAccess”:false,“targetLineLabel”:“Max”,“targetLineValue”:12.0,“baseLineLabel”:“Min”,“hideTitle”:false,“rangeAxisMaxValue”:40.0,“program”:{“id”:“YScaWpjOOnI”},“dataElementValueDimension”:{“id”:“XDtOsbxXNZq”},“relativePeriods”:{“thisYear”:false,“quartersLastYear”:false,“last52Weeks”:false,“thisWeek”:false,“lastMonth”:false,“monthsThisYear”:false,“last2SixMonths”:false,“thisQuarter”:false,“last12Months”:false,“last5FinancialYears”:false,“thisSixMonth”:false,“lastQuarter”:false,“thisFinancialYear”:false,“last4Weeks”:false,“last3Months”:false,“thisMonth”:false,“last5Years”:false,“last6BiMonths”:false,“lastFinancialYear”:false,“last6Months”:false,“quartersThisYear”:false,“monthsLastYear”:false,“lastWeek”:false,“thisBimonth”:false,“lastBimonth”:false,“lastSixMonth”:false,“lastYear”:false,“last12Weeks”:false,“last4Quarters”:false},“programStage”:{“id”:“VgrIh62C2gl”},“user”:{“id”:“RFlgWX4JP8J”},“attributeDimensions”:[],“translations”:[],“filterDimensions”:[“ou”],“organisationUnitGroups”:[],“itemOrganisationUnitGroups”:[],“userGroupAccesses”:[],“programIndicatorDimensions”:[],“columnDimensions”:[“pe”],“organisationUnitLevels”:[],“dataElementDimensions”:[{“dataElement”:{“id”:“tnY9kPc9jTh”}}],“periods”:[{“id”:“20170130”}],“organisationUnits”:[{“id”:“mS1oRZYQ41i”}],“rowDimensions”:[“tnY9kPc9jTh”]}

Updated JSON with periods set to “20170131” - as desired

{“hideLegend”: false, “baseLineLabel”: “Min”, “filterDimensions”: [“ou”], “outputType”: “EVENT”, “hideEmptyRows”: false, “periods”: [{“id”: “20170131”}], “userGroupAccesses”: [], “completedOnly”: false, “programIndicatorDimensions”: [], “attributeDimensions”: [], “id”: “QkBhkdqb8FU”, “userOrganisationUnitChildren”: false, “columnDimensions”: [“pe”], “rowDimensions”: [“tnY9kPc9jTh”], “program”: {“id”: “YScaWpjOOnI”}, “sortOrder”: 1, “targetLineLabel”: “Max”, “type”: “BAR”, “hideSubtitle”: false, “organisationUnitGroups”: [], “publicAccess”: “rw------”, “translations”: [], “userOrganisationUnit”: false, “lastUpdated”: “2017-01-31T15:32:25.206”, “organisationUnitLevels”: [], “hideNaData”: false, “userOrganisationUnitGrandChildren”: false, “dataElementValueDimension”: {“id”: “XDtOsbxXNZq”}, “baseLineValue”: 6.0, “rangeAxisMaxValue”: 40.0, “dataElementDimensions”: [{“dataElement”: {“id”: “tnY9kPc9jTh”}}], “showData”: true, “targetLineValue”: 12.0, “regressionType”: “NONE”, “programStage”: {“id”: “VgrIh62C2gl”}, “name”: “MLC Family Planning Months of Stock on Hand”, “created”: “2017-01-31T15:32:25.206”, “externalAccess”: false, “hideTitle”: false, “itemOrganisationUnitGroups”: [], “relativePeriods”: {“lastMonth”: false, “thisMonth”: false, “last6BiMonths”: false, “last5FinancialYears”: false, “lastYear”: false, “thisYear”: false, “thisWeek”: false, “monthsLastYear”: false, “last4Weeks”: false, “quartersThisYear”: false, “lastBimonth”: false, “last2SixMonths”: false, “last12Months”: false, “lastQuarter”: false, “last52Weeks”: false, “lastWeek”: false, “lastSixMonth”: false, “thisSixMonth”: false, “thisFinancialYear”: false, “last4Quarters”: false, “lastFinancialYear”: false, “thisBimonth”: false, “last12Weeks”: false, “last6Months”: false, “last5Years”: false, “quartersLastYear”: false, “thisQuarter”: false, “last3Months”: false, “monthsThisYear”: false}, “organisationUnits”: [{“id”: “mS1oRZYQ41i”}], “aggregationType”: “SUM”, “collapseDataDimensions”: false, “user”: {“id”: “RFlgWX4JP8J”}}

**JSON on the server after the request.put() **

{“lastUpdated”:“2017-01-31T15:50:29.694”,“id”:“QkBhkdqb8FU”,“created”:“2017-01-31T15:32:25.206”,“name”:“MLC Family Planning Months of Stock on Hand”,“showData”:true,“baseLineValue”:6.0,“publicAccess”:“rw------”,“userOrganisationUnitChildren”:false,“type”:“BAR”,“hideEmptyRows”:false,“userOrganisationUnit”:false,“hideNaData”:false,“regressionType”:“NONE”,“completedOnly”:false,“sortOrder”:1,“collapseDataDimensions”:false,“aggregationType”:“SUM”,“userOrganisationUnitGrandChildren”:false,“hideSubtitle”:false,“outputType”:“EVENT”,“hideLegend”:false,“externalAccess”:false,“targetLineLabel”:“Max”,“targetLineValue”:12.0,“baseLineLabel”:“Min”,“hideTitle”:false,“rangeAxisMaxValue”:40.0,“program”:{“id”:“YScaWpjOOnI”},“dataElementValueDimension”:{“id”:“XDtOsbxXNZq”},“programStage”:{“id”:“VgrIh62C2gl”},“user”:{“id”:“RFlgWX4JP8J”},“attributeDimensions”:[],“translations”:[],“filterDimensions”:[],“organisationUnitGroups”:[],“itemOrganisationUnitGroups”:[],“userGroupAccesses”:[],“programIndicatorDimensions”:[],“columnDimensions”:[],“organisationUnitLevels”:[],“dataElementDimensions”:[],“periods”:[],“organisationUnits”:[],“rowDimensions”:[]}

Forgot my manners!
Any help would be greatly appreciated!!

Thanks,

Kevin

···

On Tue, Jan 31, 2017 at 5:55 PM, Kevin Bolger kevin.bolger@gmail.com wrote:

Hi Folks,

I have an eventChart that I have saved as a favorite and added to my dashboard.

The chart uses a daily period that I would like to update each night so that the chart always showing the current (today’s) data.

I’m using a python script to get the current chart’s json (/api/eventCharts/QkBhkdqb8FU.json?fields=:owner), I then update the period value and upload (with a ‘put’ request) the updated json payload back via (/api/eventCharts/QkBhkdqb8FU.json)

The payload I put seems to have the correct data and structure, the put request response and content looks good:

<Response [200]>

{“httpStatus”:“OK”,“httpStatusCode”:200,“status”:“OK”,“response”:{“responseType”

:“ObjectReport”,“uid”:“QkBhkdqb8FU”,“klass”:"org.hisp.dhis.eventchart.EventChart

"}}

When I refresh the “/api/eventCharts/QkBhkdqb8FU.json?fields=:owner” link many of the necessary fields to define the chart selections seem to have been overwritten or the values lost.

I tried to use the request.paste() function in python but I get the following error:

<Response [500]>
{“httpStatus”:“Internal Server Error”,“httpStatusCode”:500,“status”:“ERROR”,“message”:“object references an unsaved transient instance - save the transient instance before flushing: org.hisp.dhis.program.Program”}

Below is the JSON from the original get, then the updated payload that I ‘put’ and finally what the server shows after the put.

Original: (periods is set to “20170130”

{“lastUpdated”:“2017-01-31T15:32:25.206”,“id”:“QkBhkdqb8FU”,“created”:“2017-01-31T15:32:25.206”,“name”:“MLC Family Planning Months of Stock on Hand”,“showData”:true,“baseLineValue”:6.0,“publicAccess”:“rw------”,“userOrganisationUnitChildren”:false,“type”:“BAR”,“hideEmptyRows”:false,“userOrganisationUnit”:false,“hideNaData”:false,“regressionType”:“NONE”,“completedOnly”:false,“sortOrder”:1,“collapseDataDimensions”:false,“aggregationType”:“SUM”,“userOrganisationUnitGrandChildren”:false,“hideSubtitle”:false,“outputType”:“EVENT”,“hideLegend”:false,“externalAccess”:false,“targetLineLabel”:“Max”,“targetLineValue”:12.0,“baseLineLabel”:“Min”,“hideTitle”:false,“rangeAxisMaxValue”:40.0,“program”:{“id”:“YScaWpjOOnI”},“dataElementValueDimension”:{“id”:“XDtOsbxXNZq”},“relativePeriods”:{“thisYear”:false,“quartersLastYear”:false,“last52Weeks”:false,“thisWeek”:false,“lastMonth”:false,“monthsThisYear”:false,“last2SixMonths”:false,“thisQuarter”:false,“last12Months”:false,“last5FinancialYears”:false,“thisSixMonth”:false,“lastQuarter”:false,“thisFinancialYear”:false,“last4Weeks”:false,“last3Months”:false,“thisMonth”:false,“last5Years”:false,“last6BiMonths”:false,“lastFinancialYear”:false,“last6Months”:false,“quartersThisYear”:false,“monthsLastYear”:false,“lastWeek”:false,“thisBimonth”:false,“lastBimonth”:false,“lastSixMonth”:false,“lastYear”:false,“last12Weeks”:false,“last4Quarters”:false},“programStage”:{“id”:“VgrIh62C2gl”},“user”:{“id”:“RFlgWX4JP8J”},“attributeDimensions”:,“translations”:,“filterDimensions”:[“ou”],“organisationUnitGroups”:,“itemOrganisationUnitGroups”:,“userGroupAccesses”:,“programIndicatorDimensions”:,“columnDimensions”:[“pe”],“organisationUnitLevels”:,“dataElementDimensions”:[{“dataElement”:{“id”:“tnY9kPc9jTh”}}],“periods”:[{“id”:“20170130”}],“organisationUnits”:[{“id”:“mS1oRZYQ41i”}],“rowDimensions”:[“tnY9kPc9jTh”]}

Updated JSON with periods set to “20170131” - as desired

{“hideLegend”: false, “baseLineLabel”: “Min”, “filterDimensions”: [“ou”], “outputType”: “EVENT”, “hideEmptyRows”: false, “periods”: [{“id”: “20170131”}], “userGroupAccesses”: , “completedOnly”: false, “programIndicatorDimensions”: , “attributeDimensions”: , “id”: “QkBhkdqb8FU”, “userOrganisationUnitChildren”: false, “columnDimensions”: [“pe”], “rowDimensions”: [“tnY9kPc9jTh”], “program”: {“id”: “YScaWpjOOnI”}, “sortOrder”: 1, “targetLineLabel”: “Max”, “type”: “BAR”, “hideSubtitle”: false, “organisationUnitGroups”: , “publicAccess”: “rw------”, “translations”: , “userOrganisationUnit”: false, “lastUpdated”: “2017-01-31T15:32:25.206”, “organisationUnitLevels”: , “hideNaData”: false, “userOrganisationUnitGrandChildren”: false, “dataElementValueDimension”: {“id”: “XDtOsbxXNZq”}, “baseLineValue”: 6.0, “rangeAxisMaxValue”: 40.0, “dataElementDimensions”: [{“dataElement”: {“id”: “tnY9kPc9jTh”}}], “showData”: true, “targetLineValue”: 12.0, “regressionType”: “NONE”, “programStage”: {“id”: “VgrIh62C2gl”}, “name”: “MLC Family Planning Months of Stock on Hand”, “created”: “2017-01-31T15:32:25.206”, “externalAccess”: false, “hideTitle”: false, “itemOrganisationUnitGroups”: , “relativePeriods”: {“lastMonth”: false, “thisMonth”: false, “last6BiMonths”: false, “last5FinancialYears”: false, “lastYear”: false, “thisYear”: false, “thisWeek”: false, “monthsLastYear”: false, “last4Weeks”: false, “quartersThisYear”: false, “lastBimonth”: false, “last2SixMonths”: false, “last12Months”: false, “lastQuarter”: false, “last52Weeks”: false, “lastWeek”: false, “lastSixMonth”: false, “thisSixMonth”: false, “thisFinancialYear”: false, “last4Quarters”: false, “lastFinancialYear”: false, “thisBimonth”: false, “last12Weeks”: false, “last6Months”: false, “last5Years”: false, “quartersLastYear”: false, “thisQuarter”: false, “last3Months”: false, “monthsThisYear”: false}, “organisationUnits”: [{“id”: “mS1oRZYQ41i”}], “aggregationType”: “SUM”, “collapseDataDimensions”: false, “user”: {“id”: “RFlgWX4JP8J”}}

**JSON on the server after the request.put() **

{“lastUpdated”:“2017-01-31T15:50:29.694”,“id”:“QkBhkdqb8FU”,“created”:“2017-01-31T15:32:25.206”,“name”:“MLC Family Planning Months of Stock on Hand”,“showData”:true,“baseLineValue”:6.0,“publicAccess”:“rw------”,“userOrganisationUnitChildren”:false,“type”:“BAR”,“hideEmptyRows”:false,“userOrganisationUnit”:false,“hideNaData”:false,“regressionType”:“NONE”,“completedOnly”:false,“sortOrder”:1,“collapseDataDimensions”:false,“aggregationType”:“SUM”,“userOrganisationUnitGrandChildren”:false,“hideSubtitle”:false,“outputType”:“EVENT”,“hideLegend”:false,“externalAccess”:false,“targetLineLabel”:“Max”,“targetLineValue”:12.0,“baseLineLabel”:“Min”,“hideTitle”:false,“rangeAxisMaxValue”:40.0,“program”:{“id”:“YScaWpjOOnI”},“dataElementValueDimension”:{“id”:“XDtOsbxXNZq”},“programStage”:{“id”:“VgrIh62C2gl”},“user”:{“id”:“RFlgWX4JP8J”},“attributeDimensions”:,“translations”:,“filterDimensions”:,“organisationUnitGroups”:,“itemOrganisationUnitGroups”:,“userGroupAccesses”:,“programIndicatorDimensions”:,“columnDimensions”:,“organisationUnitLevels”:,“dataElementDimensions”:,“periods”:,“organisationUnits”:,“rowDimensions”:}

1 Like

Hi, I know this is an old post but I am currently having the same difficulty trying to update the periods for a chart using the API and python. Were you ever able to solve this issue?

1 Like