I want to be able to fetch visualizations from the metadata API, perform modifications programmatically and post the modified objects to DHIS2 via the API as new visualizations. However, when performing post requests to the visualization endpoint, the new visualisations lack dataDimensionItems, organisationUnits, periods etc. as well as the columnDimensions, rowDimensions and filterDimensions fileds. This leads to empty visualizations in practice. Why is this?
I could use the metadata endpoint instead, but in that case, I have sometimes struggled to get the correct sharing settings for the posted objects when performing post requests to the metadata endpoint. What is the intended method for posting metadata to DHIS2? Is it better to use the metadata endpoint in general, or am I correct in assuming that I should generally use the specific endpoints for specific metadata types (like visualizations)?
Without practical information, I’d be theorizing and not being able to help much. It’s not clear why the empty visualization is returned. Are you not able to create a basic visualization? What version are you using?
Can we try to replicate this on play.dhis2.org for testing?
I tried to send a POST request to (Login app | DHIS2) with the body:
Based on your explanation at first is that your use case requires that you create visualizations using the API which means you’d already have metadata and data created, so could you explain how using the metadata endpoint solves this?
Remove the id attribute and change the name to “test123” in a text editor locally.
Perform a post request to /api/visualizations with the modified JSON object as body.
Open the test123 visualization in the data visualizer app. It will not show any data.
So the point is not that the visualization is not created, but rather that posting a visualization json retrieved from the visualization or metadata endpoint to the visualization endpoint will lead to an empty visualization, and I wonder why that is.
Hello,
after having a chat with @augustsm, we concluded that the best way to save a new Visualization from an existing one, is to mimic the requests used by the FE application (Data Visualizer), during a “Save as” operation. In this way we guarantee that all necessary payload/data is correctly fetched and saved.
The main point of the discussion was the use case related to data migration. For such situations, it’s better to use something like export/import (metadata) or find a solution that ensures that all Visualization data and its relationships will be correctly migrated/copied.