Add list of device IDs as a filter to the Search Device Inventories route

Hello everyone,

Currently I have the use case that I want to search for a device by ID and limit the response attributes.

Unfortunately, there is currently (Mender 3.6) no Management API route to implement this use case.

With the Management APIs > Device inventory > Get Device Inventory route, I can search for a device by ID, but I cannot limit the attributes.

With the Management APIs > Device inventory filters and search > Search Device Inventories route, I can limit the attributes, but not search by ID.

Both functions are covered by the Internal APIs > Device inventory filters and search > Search Device Inventories route, but unfortunately this is not exposed.

For this reason, I would like to request a feature.

As with the Internal API, I would like to be able to enter a list of device IDs when searching in order to filter.

Would it be possible to implement this feature?

Best regards and many thanks in advance!

Kevin

Hi @k.kasper,

Thanks for getting in touch. The filter $in should provide exactly the functionality you are looking for, and is available in the Professional and Enterprise tiers.

EDIT: this snippet should get you going:

fetch('https://hosted.mender.io/api/management/v2/inventory/filters/search', {
  headers: { authorization: 'Bearer <JWT>' },
  body: {
    page: 1,
    per_page: 20,
    filters: [
      { scope: 'identity', attribute: 'id', type: '$in', value: ['<deviceIds>'] },
      { scope: 'identity', attribute: 'status', type: '$eq', value: 'accepted' }
    ],
    attributes: [{ scope: 'identity', attribute: 'status' }]
  },
  method: 'POST'
});

Greetz,
Josef

Thank you, it works wonderfully!

I didn’t realise that the ID is also defined as an attribute :slight_smile:

1 Like