Hello,
All is in the title,
To VCvirtualmachine object input i'm looking for a way to extract the iaas ID of a VM, tried some REST but didnt found yet anything useful
id.content is an array, being a search result
Check its length and use id.content[0].id if the result contains only one element.
externalId": "5031a44b-5142-2193-619c-055bdb153fa9",
"name": "TEST",
"description": "TEST ",
"id": "a3cdcd16-5a30-4883-ac7a-93fa48b31b09",
i want to avoid to fetch by API all items of a deployment to get the VM
API is https://<vra fqdn>iaas/api/machines/a3cdcd16-5a30-4883-ac7a-93fa48b31b09
Try /iaas/api/machines?$filter=externalId%20eq%205031a44b-5142-2193-619c-055bdb153fa9
Yes filter would work but it would assume that i've already the ID which is not the case because i just have in input the vcVM virtulmachine and as far as i know there's no generic API to fetch all those ID
externalId is the VM's instanceId:
vm.instanceId
=> 5035a142-da26-a422-083e-547337c4b961
/iaas/api/machines?$filter=externalId+eq+%275035a142-da26-a422-083e-547337c4b961%27
should give you the same VM
Sounds great but There is something i shoud miss:
Get iaas/api/machines?$filter=externalId+eq+%5031a44b-5142-2193-619c-055bdb153fa9%27
{
"message": "undetermined string (externalId eq P31a44b-5142-2193-619c-055bdb153fa9') and (type eq 'VM_GUEST')",
"statusCode": 400,
"errorCode": 0,
Get iaas/api/machines/a3cdcd16-5a30-4883-ac7a-93fa48b31b09
"externalId": "5031a44b-5142-2193-619c-055bdb153fa9",
"name": "VMPrefix.000934",
"description": "TEST",
"id": "a3cdcd16-5a30-4883-ac7a-93fa48b31b09",
%27 is '
you should have at both before and after the actual ID
Thanks didnt spot that ( looks like i'm little bit tired 😉
iaas/api/machines?$filter=externalId+eq+%275031a44b-5142-2193-619c-055bdb153fa9%27
{
"content": [],
"totalElements": 0,
"numberOfElements": 0
}
do i need to specify a field?
By filtering by VM.name it seems ok to fetch the ID i'll test it!
var vmname = VM.name;
--> Go to a worklow that generate a REST API
var url_input = url_input + '?$filter=name+eq+' + "'" + vmname + "'";
Now left to parse 😉
With VM name it works but at least i'm stuck by parsing the answer of the rest api:
tried this but my var parsed is empty, could you help me to parse the ID field?
Here s my scriptable task:
var id = JSON.parse(result.contentAsString );
var parsed = id.content.id;
System.log("result " + parsed);
id.content is an array, being a search result
Check its length and use id.content[0].id if the result contains only one element.