Assign inventory roles to device groups using the Java SDK


Is there a way to assign an Inventory role to the newly created device group using the Java SDK?
I was not able to find a way to perform this operation in the Java SDK documentation.

I was able to create a device group using the Java SDK:

ManagedObjectRepresentation mor = new ManagedObjectRepresentation();		
mor.setProperty("c8y_IsDeviceGroup", "");			
mor = inventoryApi.create(mor);

Add the existing device to this group:

ManagedObject mob = inventoryApi.getManagedObjectApi(deviceGroupGID);		

How could I add the Inventory role for an user, so I could grant him access to this group?

My assumption is that there should be a way to add InventoryAssignmentRepresentation to the user, which contains managed Object (device group) and inventory roles for this representation. Unfortunately, I was not able to find a way to do this.

I have already posted a similar question regarding the API requests:
Assign inventory roles to device groups using the API


Hi Nikola,

sorry for the late reply! Unfortunately this is not implemented in the Java SDK but you can easily implement that yourself using the SDK.
Use the platform Object and call “.rest()” which gives you a full authenticated rest client. With post and following this documentation Users - Cumulocity IoT Guides you can send a post request to do this.

To generate the required JSON string you can either use Jackson (ObjectMapper) to create a new object are serialize a class matching the required payload structure e.g.