Solved

Rest API - GET VM (lists info of all VMs) - how to get complete record info for a particular VM?


Userlevel 2
Badge +8

https://documentation.commvault.com/v11/essential/125353_rest_api_get_virtual_machines.html

GET <webservice>/VM operation give us the  list of virtual machines

it gives almost all the info about the VM, like latest backupjobid, vmsize, the virtualization client info, subclientid, clientid etc.

 

Instead of listing all VMs’ i want this info for a specific VM, how shall i fiilter out the info for a VM in this API operation.

 

2 methods that i tried are, but this isn’t giving me complete info 

GET <webservice>/VM?Search=vmStatusInfoList.client.clientName%3Acontains%3Axpath:{/workflow/inputs/source_vm}&
GET <webservice>/VM?Search=vmStatusInfoList.vsaSubClientEntity.subclientName%3Acontains%3Axpath:{/workflow/inputs/source_vm}&

 

but I’m not getting the complete info of that VM, i would like to retrieve the whole record info for a specific VM.

 

Example:

Sample response of Get VM

=========================

"totalRecords":5,"pageNo":0,"errorMessage":"","errorCode":0,"pageSize":100,"vmStatusInfoList":[
{
"vmHost":"",
"bkpStartTime":1665719167,
"type":9,"vmStatus":1,
"slaStatus":1,
"vmUsedSpace":6442642704,
"isFSAgentBackedUp":true,
"subclientId":1234,
"bkpEndTime":1665719336,
"vmFailureReasonForWarning":"",
"name":"vmtest1",
"storagepolicyName":"VM_IntelliSnap_StoragePolicy",
"slaCategory":1,
"vmGuestSpace":6442642704,
"latestBackupTimeCatalogedSuccessfully":0,
"isIndexingV2":true,
"vmBackupJob":1234567,
"strOSName":"windows-server-2012-r2-dc",
"isDeleted":false,"vendor":16,
"osType":1,
"applicationSize":6442642704,
"vmSize":6442642704,
"slaCategoryDescription":"Protected",
"vmAgent":"cvltproxy",
"retireClientPhase":0,
"isContentIndexded":false,
"isBackupAllowed":true,
"vmHardwareVer":"",
"strGUID":"1234567891234567891",
"subclientName":"vmtest1_2_daily",
"vsaNextBackupSubClientEntity":{"backupsetId":4321,"subclientId":1234,"subclientName":"vmtest1_2_daily","flags":{}

},"instanceEntity":{
"instanceId":1677
},"commCell":{
"_type_":1,"commCellName":"cvltserver","csGUID":"test-1234-TEST-1234"
},"proxyClient":{
"clientId":9123,"clientName":"cvltproxy"
},"plan":{

},"vsaSubClientEntity":{
"backupsetId":4321,"subclientId":1234,"subclientName":"vmtest1_2_daily"
},"client":{
"clientId":2345,"clientName":"vmtest1","displayName":"vmtest1","flags":{
"include":true
}
},"pseudoClient":{
"clientId":5678,"clientName":"IntelliSnap_VM","flags":{
"disabled":false
}
},"lastBackupJobInfo":{
"jobID":1234567,"commCellID":9,"failureReasonMessageEnglish":"","status":1,"startTime":{
"time":1665719167
},"endTime":{
"time":1665719445
}
},

 

 


....similar other records for remaining VM’s

 


]

icon

Best answer by christopherlecky 17 October 2022, 16:00

View original

12 replies

Userlevel 7
Badge +19

@alligator what is the use-case? if you are writing code yourself then you could very easily filter it out yourself, right? in case you are running a recent version it might be worth looking at the newer API implementations, but retrieving specific VM information always requires a lookup for the unique identifier to be able to pull detailed information, related to the specific VM, from the API. 
 

 

Userlevel 2
Badge +8

@Onno van den Berg so you mean to say, first i must do a GET VM, from the output i must extract the VMUUID and then perform a GET/VirtualMachines/{vmUUID}

 

Userlevel 7
Badge +19

@alligator correct but in case the GET VM call already extract the required information that you can filter it out from there yourself. 

Userlevel 2
Badge +8

 @Onno van den Berg thank you 

yes i was specifically looking to fetch the subclientID from the record for the given client.

So i will be giving the vm name as the input and i want the subclientid to be fetched, so in next step i can do a “DoBrowse” using that

So was looking for an easy way to achieve that.. :) 😬

 

Userlevel 5
Badge +16

The simplest way to achieve that is to charge your http request to return XML rather than JSON 

and then use an xpath query.

 

 

 

 

You could prototype it using an online xpath editor like this one https://xmlgrid.net/xpath.html

It’s basically a query against the xml output that you could use to filter for what you want.

 

It would be much easier if there was a jsonpath activity built into the workflow system 

 

Userlevel 5
Badge +16

Alternatively you can import the JSON input into script convert it into a Java/JS object and extract your data that way.

Userlevel 2
Badge +8

@Onno van den Berg @christopherlecky 

Thanks alot for the answers.

Xpathquery seems to be the easiest way to me

 

but i’m finding it a bit difficult to find the query . it works when the value is a number

:(

//vmStatusInfoList/client[clientId=4]/clientName

 

This way its giving me the output , but i need the info the other way, i would pass the vm name, i need the clientID/subclientID etc.

 

//vmStatusInfoList/client[clientName='ty-vm']/clientId
 

 

Also i couldn’t find any sample for XPathQuery activity in other standard built-in workflow.

Is there any that you know which i can refer to 

Userlevel 5
Badge +16

The reason I didn’t just give the xpath string is because the json output you entered was malformed,

 

Can you post the JSON/XML output in it’s entirety and I’ll give you xpath string you need to get you what you want.

 

Note: I am pressed for time so I may not get back to this today.

Userlevel 2
Badge +8

here is a sample xml, so i only have the vm name,

from this GET VM xml output, i want to find the subclientId of the given vm

 

 

name
vm client info (client/(s) added in the subclient)

 

Userlevel 2
Badge +8

thanks alot in advance

Userlevel 2
Badge +8

I think i found the XPath Query to get the subclientId for the specific vm

 

 

Userlevel 5
Badge +16

Awesome, does it work?

 

I was hoping you would list the xml in a code snippet rather than as an attachment, I don’t really have the time to download import and modify the xml. 

 

I just pop in from time to time when I get stuck on something.

Reply