VMware Cloud Community
bdamian
Expert
Expert

API call to know user's owned items

Is there any API method to get a list of "owned items" for a given user?

Thanks a lot,

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Tags (2)
Reply
0 Kudos
3 Replies
mikestevenson00
Contributor
Contributor

There is, I've been working with something similar lately myself.  If you GET https://<vrahost>/catalog-service/api/consumer/resources you get back a list of all current items.  There's some filtration available, and I would imagine owner is one of the parameters (I've personally only filtered on the item name).  The programming guide and API reference here should have the info you need to get going.

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

Here is a vRO action that I use to grab that sort of information.  Hope this is helpful in some way.

var service = host.createCatalogClient().getCatalogConsumerResourceService();

var xObj = [];

var userArr = JSON.parse(userList.toLowerCase());

if (userArr instanceof Array != true) {

  throw "Expected an array to be parsed.  Check input string: " + userList;

}

for each (var user in userArr) {

  xObj.push({"userid" : user,"username" : "","machines" : []});

  var userIndex = userArr.indexOf(user);

  var filter = new Array();

  filter[0] = vCACCAFEFilterParam.substringOf("owners/ref", vCACCAFEFilterParam.string(user));

  var query = vCACCAFEOdataQuery.query().addFilter(filter);

  var items = service.getResourcesList(new vCACCAFEPageOdataRequest(query));

  for each (var item in items) {

// System.log("Item: " + item.name + " owned by: " + user);

  xObj[userIndex].machines.push(item.name);

  }

}

var objOut = JSON.stringify(xObj);

System.log("Return value stringified: ");

System.log(objOut);

Reply
0 Kudos
muxx
Enthusiast
Enthusiast

This is the call that web is using:

/api/consumer/resources/types/Infrastructure.Machine/?$top=30&$skip=0&$orderby=name asc&$filter=ownersref eq 'user@company.local'

However it is not documented in API documentation. According to api doc, you should use /api/consumer/resources/ address as described here

vRealize Automation 6.2 Documentation Center

User can see his items. Manager/Admin can see VMs owned by his users. User cannot see other users VMs.

Reply
0 Kudos