External id of a managed object

I wan to find externalIds of all the managed objects in the tenant
Java version: 17
c8y_backend: 1020.73.0

try {
            InventoryFilter inventoryFilter = new InventoryFilter();
            inventoryFilter.byFragmentType("c8y_IsDevice");
            ManagedObjectCollection managedObjectsByFilter = inventoryApi.getManagedObjectsByFilter(inventoryFilter);
            List<ManagedObjectRepresentation> allObjects = Lists.newArrayList(managedObjectsByFilter.get().allPages());
            for(int i = 0 ; i < allObjects.size(); i++){
                ManagedObjectRepresentation managedObjectRepresentation = allObjects.get(i);
                String externalId = getExternalId(managedObjectRepresentation.getId().getValue());
            }
public String getExternalId(String value) {

       ExternalIDRepresentation externalIDRepresentation = identityApi.getExternalId(new ID(value));
       return externalIDRepresentation.getExternalId();

    }

But it is giving error in getting externalIds

Did you try using identity.getExternalIdsOfGlobalId​(GId gid) instead of identityApi.getExternalId(ID extId) ?

You are mixing things up. While you retrieving the internal managed Object ID you call the identity API to retrieve the external ID by the external ID String + type String (external ID != internal managed Object ID)

If you get the Gid by the managed Object you should also use it like this:

ExternalIDRepresentation externalIDRepresentation = identityApi.getExternalIdsOfGlobalId​(managedObjectRepresentation.getId());

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