Get Inventory Roles via SDK

Using the Microservice SDK 10.9 I would like to retrieve the inventory roles for a user X.

Is this at all possible using the UserAPI?

Via REST, the call would look like {{url}}/user/{{tenantId}}/users/{{userID}}/roles/inventory

thanks

The UserApi does not implement this API call.

You would need to implement it yourself, e.g. using the “RestConnector” class and leverage the already existing Rest-Representation class “InventoryAssignmentCollectionRepresentation”:

import com.cumulocity.rest.representation.CumulocityMediaType;
import com.cumulocity.rest.representation.user.InventoryAssignmentCollectionRepresentation;
import com.cumulocity.sdk.client.RestConnector;

[...]

@Autowired
private RestConnector restConnector;

[...]
InventoryAssignmentCollectionRepresentation inventoryRoleAssignment = restConnector
	.get("/user/" + tenantId + "/users/" + userID + "/roles/inventory",
		CumulocityMediaType.APPLICATION_JSON_TYPE,
		InventoryAssignmentCollectionRepresentation.class);

(*) code is not tested

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.