我正在尝试使用库存 API 将子设备设置为 Cumulocity 中的设备,遗憾的是没有成功。
我已经尝试过以下操作:
GId gid = new GId(deviceId);
ManagedObjectRepresentation deviceRepresentation = inventoryApi.get(gid);
ManagedObjectReferenceCollectionRepresentation childDevices = new ManagedObjectReferenceCollectionRepresentation();
ManagedObjectReferenceRepresentation morr = new ManagedObjectReferenceRepresentation();
morr.setManagedObject(mo);
List<ManagedObjectReferenceRepresentation> references = new ArrayList<ManagedObjectReferenceRepresentation>();
references.add(morr);
childDevices.setReferences(references);
deviceRepresentation.setChildDevices(childDevices);
deviceRepresentation.setLastUpdatedDateTime(null);
inventoryApi.update(deviceRepresentation);
没有抛出错误,但之后,当我查看 list 时,设备都没有设置 childDevices,托管对象也没有设置 deviceParents。 我做错了什么?
最佳答案
子设备和 Assets 是使用专用端点设置的,而不是通过更改托管对象中的子列表来设置。请参阅https://cumulocity.com/guides/reference/inventory/#managed-object-reference-collection了解详情。
在您使用 java-client 的情况下,您可以这样做:
GId parentID = new GId(deviceId);
GId childId = new GId(childDeviceId);
ManagedObject managedObjectApi = inventoryApi.getManagedObjectApi(parentID);
managedObjectApi.addChildDevice(childId);
关于children - 如何通过 inventory api 将子设备设置为设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57359043/