VMware Cloud Community
raidriddle
Contributor
Contributor
Jump to solution

REST API JSON VC:VmFolder

I am attempting to kick off a workflow via REST/JSON. The workflow takes two inputs:

     1. a string variable called vmName - self explanatory.

     2. a VC:VmFolder variable called FolderName - I have to get the VMs Folder in order to do some cloning. the issue is that I only have a folder name since that is the interface level my users are working at.

Once the Workflow has been called it kicks off a slew of cloning, snapshot, etc activity.

I pass in the following JSON and I get back an error message complaining about the request being "Syntactically Incorrect".

I know my issue is with the way the JSON is structured with regard to the VC:VmFolder as that is an object and not a basic type (string, number). How do I structure the call correctly and more importantly is there a good set of documentation or reference website that will guide me down the right path in the future when dealing with this or other complex data types / objects - I want to learn to fish?

  1.     "parameters"
  2.     [ 
  3.         { 
  4.             "name":"vmName"
  5.             "type":"string"
  6.             "value":{"string":{"value":"MyVMName"}} 
  7.         }, 
  8.         { 
  9.             "name":"vcFolder"
  10.             "type":"VC:VmFolder"
  11.             "value":{"VC:VmFolder":{"value":"folderName"}} 
  12.         } 
  13.  
  14.  
  15.     ] 

Any help is greatly appreciated.

Thank you.

1 Solution

Accepted Solutions
Burke-
VMware Employee
VMware Employee
Jump to solution

Okay, so here's your fishing pole pre-baited in a pond full of fish Smiley Wink

The attached workflow has the id used here (obviously you'll need to update the URL:port with your server in order to test this):

https://vra-01a.corp.local:443/vco/api/workflows/f40c35ce-1c89-492f-8e33-0eee13d836cc/executions

Here's the body to send via json:

{

  "parameters": [{

  "value": {

  "string": {

  "value": "DemoVM2"

  }

  },

  "type": "string",

  "name": "vmName",

  "scope": "local"

  }, {

  "value": {

  "string": {

  "value": "Management"

  }

  },

  "type": "string",

  "name": "vmFolderName",

  "scope": "local"

  }]

}

The run in the screenshot here was initiated using the Postman rest client with the request url and json body shown above. As you can see, there are string based inputs.

Screen Shot 2016-04-15 at 1.39.57 PM.png

The output provided is a VC:VmFolder object

Screen Shot 2016-04-15 at 1.42.18 PM.png

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter

View solution in original post

0 Kudos
6 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

The value of the folder is not its name.

Either you change your workflow to take a folder name as input (and add javascript code to get folder from name or you run the workflow once from the client and check the workflow run from rest to check the format of the vmfolder (which certainly include the vCenter managed object reference). There is a tutorial here How to use the REST API to Start a Workflow

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Christophe has pointed you to the best source for this topic.. and I'm not just saying that because I'm the author Smiley Wink

To further illustrate, here's what your json body should resemble:

{

  "parameters": [{

  "value": {

  "string": {

  "value": "DemoVM2"

  }

  },

  "type": "string",

  "name": "vmName",

  "scope": "local"

  }, {

  "value": {

  "sdk-object": {

  "type": "VC:VmFolder",

  "href": "https://vra-01a.corp.local:443/vco/api/catalog/VC/VmFolder/vcsa-01a.corp.local%252Fgroup-v41/",

  "id": "vcsa-01a.corp.local/group-v41"

  }

  },

  "type": "VC:VmFolder",

  "name": "vcFolder",

  "scope": "local"

  }]

}

Note the sdk-object, it is constructed of the href url to your vRO server inventory object for the selected VmFolder, and the id of the vmfolder object. Please note that the port in my sample is 443 because this was run against a vRO 7 server that is embedded in the vRA appliance. If you were running against a standalone vRO server, it would be port 8281.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

I just went a step further and tried a REST call with a query built into the url:

https://vra-01a.corp.local:443/vco/api/catalog/VC/VmFolder?conditions=name%3DManagement

When I do a GET request against that URL, here are the results, an array of objects since I have two vCenters connected to my environment. As you can see, the information necessary for the json body in my previous post is available here:

{

  "link": [

    {

      "attributes": [

        {

          "value": "vcsa-01b.corp.local/group-v203",

          "name": "dunesId"

        },

        {

          "value": "VmFolder",

          "name": "@type"

        },

        {

          "value": "Management",

          "name": "name"

        },

        {

          "value": "group-v203",

          "name": "id"

        },

        {

          "value": "https://vcsa-01b.corp.local:443/sdk",

          "name": "vimHost"

        },

        {

          "value": "VmFolder",

          "name": "type"

        }

      ],

      "href": "https://vra-01a.corp.local:443/vco/api/catalog/VC/VmFolder/vcsa-01b.corp.local%252Fgroup-v203/",

      "rel": "down"

    },

    {

      "attributes": [

        {

          "value": "vcsa-01a.corp.local/group-v41",

          "name": "dunesId"

        },

        {

          "value": "VmFolder",

          "name": "@type"

        },

        {

          "value": "Management",

          "name": "name"

        },

        {

          "value": "group-v41",

          "name": "id"

        },

        {

          "value": "https://vcsa-01a.corp.local:443/sdk",

          "name": "vimHost"

        },

        {

          "value": "VmFolder",

          "name": "type"

        }

      ],

      "href": "https://vra-01a.corp.local:443/vco/api/catalog/VC/VmFolder/vcsa-01a.corp.local%252Fgroup-v41/",

      "rel": "down"

    }

  ],

  "total": 2

}

If you wanted to further narrow down the results of a query, you could also filter on the vimHost:

https://vra-01a.corp.local:443/vco/api/catalog/VC/VmFolder?conditions=name%3DProduction%2CvimHost%3D...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
raidriddle
Contributor
Contributor
Jump to solution

Thanks for the feedback both you and Burke. I saw the tutorial some time ago and am able to run most of the basic workflows via REST. The solution that Burke gave below was close to what I needed. I see based on his example how to track down the required data for the REST request so that was very helpful. Unfortunately, it also led me to the belief that cdecanini is correct to that I may have to pass a string and find the folder in Code. The issue with Burke's solution is that I simply have a tree view for my customer to chose from and all I get back is the folder name. they have no way to pass me the ID. I have the ability to form JSONs for the request but not loop through the XML returned by VCO in order to find the ID associated with a specific folder name (One VCSA so unique folder/object names throughout). So I've been banging my head against the code wall for most of today and I don't see a way to loop through the VmFolders to do a name comparison.

Thanks again.

0 Kudos
Burke-
VMware Employee
VMware Employee
Jump to solution

Okay, so here's your fishing pole pre-baited in a pond full of fish Smiley Wink

The attached workflow has the id used here (obviously you'll need to update the URL:port with your server in order to test this):

https://vra-01a.corp.local:443/vco/api/workflows/f40c35ce-1c89-492f-8e33-0eee13d836cc/executions

Here's the body to send via json:

{

  "parameters": [{

  "value": {

  "string": {

  "value": "DemoVM2"

  }

  },

  "type": "string",

  "name": "vmName",

  "scope": "local"

  }, {

  "value": {

  "string": {

  "value": "Management"

  }

  },

  "type": "string",

  "name": "vmFolderName",

  "scope": "local"

  }]

}

The run in the screenshot here was initiated using the Postman rest client with the request url and json body shown above. As you can see, there are string based inputs.

Screen Shot 2016-04-15 at 1.39.57 PM.png

The output provided is a VC:VmFolder object

Screen Shot 2016-04-15 at 1.42.18 PM.png

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you!

Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator
for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
raidriddle
Contributor
Contributor
Jump to solution

Burke, If you are ever in Orlando I owe you lunch. I see what you did thanks for the pole and the fish. My major blocker was not knowing about VcPlugin - I looked that up and found the function calls that go with it and that is going to solve most of the issues I think I'm going to run into. Thank you!