Hi,
it’s Luca from DAC System.
This question is related to this former topic.
For automatic testing porpouses, we need to modify a dashboard programmatically. In particular, at the moment we need to delete a map widget.
The tests are perfomed on the home section of a custom Cockpit application. So, the application looks like this
On the inventory collection the home looks like this (im using Postman to simulate what I would code):
{
"additionParents": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/additionParents"
},
"owner": "kai.reinhardt@softwareag.com",
"childDevices": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/childDevices"
},
"childAssets": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/childAssets"
},
"creationTime": "2022-02-22T08:10:20.786Z",
"lastUpdated": "2023-12-18T09:10:57.719Z",
"childAdditions": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/childAdditions"
},
"assetParents": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/assetParents"
},
"deviceParents": {
"references": [],
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200/deviceParents"
},
"self": "https://t1358926305.cumulocity.com/inventory/managedObjects/1200",
"id": "1200",
"c8y_Dashboard!name!home-cockpit1": {},
"c8y_Global": {},
"c8y_Dashboard": {
"children": {
"799324260951046": {
"componentId": "cluster-map-widget",
"classes": {
"card-dashboard": true,
"panel-title-regular": true,
"cluster-map-widget": true,
"card": true
},
"_x": 0,
"_y": 0,
"id": "799324260951046",
"title": "Cluster Map",
"_width": 7,
"config": {},
"_height": 7
}
},
"classes": {
"dashboard-theme-transparent": true
},
"c8y_IsNavigatorNode": null,
"widgetClasses": {
"panel-title-regular": true
},
"isFrozen": false
}
}
My initial approach is to get the id of the cluster-map-widget and just delete it. To know if I’m getting things right I try to retrieve the widget with the following query
/inventory/managedObjects/7967897646768485
Result:
{
"error": "inventory/Not Found",
"message": "Finding device data from database failed : No managedObject for id '7967897646768485'!",
"info": "https://www.cumulocity.com/guides/reference/rest-implementation//#a-name-error-reporting-a-error-reporting"
}
So widgets instances are not MO (?). If so I cannot use the inventory API to delete a widget even though I know its Id.
The only solution I see to this problem is to get the home MO and update it. Any better option? Am I missing something again?
BONUS: to retrieve the Home MO I’m performing this query:
/inventory/managedObjects?fragmentType=c8y_Dashboard!name!home-cockpit1
Any better solution? Is this ok?
Best
Luca