Is there any API to find list of devices for which user is having access to?
Unfortunately there is no API to retrieve the devices for specific users but if the user authenticates himself against a custom microservice you can retrieve all the devices he has access to via the default inventory API. Permission checks are done in the background and all devices returned, the user has access to.
The issue is that the inventory roles assigned to a user can be pretty complex (e.g. several groups with different permissions). The platform itself also just using inventory API to check which devices to be returned based on the given permissions.
What’s the purpose of this? What do you want to achieve by retrieving the devices of users? Maybe I can point you to other solutions if I understand what you want to achieve.
This is for a reporting requirement, where we want to fetch the details of devices onboarded in last one month and assigned to which user.
Using inventory API i could fetch the device details but not able find to whom(user) this devices is assigned to?
As @Stefan_Witschel explained, the inventory API does not support querying for the objects a specific user has access to. If you are running inside a microservice, and you are creating the report on behalf of a specific user who has initiated the report by calling a REST endpoint on the microservice, you can actually use the user context. Any call to service provided by the Java SDK is by default inside the user’s context (unless ýou explicitly perform “callForTenant”). This means any call to the inventory API will only return the devices the user has access to.
As this has to be done in response to a REST call by one specific user, it will not help if you want to create a report on a schedule or if you want to create a report for multiple users.
if I understand your requirement correct you want to provide reports which devices are assigned to which users. Per concept devices are not assigned to users in Cumulocity IoT. They only have an owner (which could also be a non-human technical user) and permissions which allow you to access groups of devices, but I see two ways how you can achieve your report.
In each Device managed object you can add a custom fragment where you maintain all the users the device is assigned to. Also you need a microservice or UI to assign users to devices, as I stated, this is not a default concept of Cumulocity IoT.
You can create groups for each user and assign the devices to it. Also you can adapt the inventory roles accordingly. So you have a 1:n user to device relation within a group. Now you need to retrieve the groups for each users and check which devices are assigned to it.