API to find User's devices

Product/components used and version/fix level:

Detailed explanation of the problem:

Is there any API to find list of devices for which user is having access to?

Error messages / full error message screenshot / log file:

Question related to a free trial, or to a production (customer) instance?

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.

Hi @punam90singh

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.

  1. 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.

  2. 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.

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