Exploring vSphere 6.5 API-Part 1: Datacenter & Cluster

I am using API for quite a bit now in our prod environment which is based on vCloud Director and many times API’s had proved a handy way to troubleshoot issues where GUI was not providing a way to proceed.

Inspired by vCD API’s, i decided to test that in my vSphere 6.5 lab and in this post I will try to demonstrate few queries which can be helpful in fetching info in your infrastructure.

In my lab I am exploring REST API’s using a linux tool called curl.

1: You can browse list of API’s by browsing https://vc-fqdn/ and clicking on “Browse vSphere Rest API’s”



2: To start with you can use below query to see what are the different options available

# curl -sik -H ‘Accept:application/json’ -u “vc-user” -X GET https://vc-fqdn/rest/

You will see below URL’s in output:



3: You can list the available components which can be explored via REST API by using below query

# curl -sik -H ‘Accept:application/json’ -u “vcadmin@alex” -X GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/component

Available Options

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vcenter.ovf

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=applmgmt

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.cis

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vcenter.inventory

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vcenter

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vapi.vcenter

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.cis.tagging

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.content

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=vmon_vapi_provider

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vapi.rest.navigation

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vcenter.iso

GET https://vcentersrv03.alex.local/rest/com/vmware/vapi/rest/navigation/service?component_id=com.vmware.vapi

Let’s start with exploring available options for Datacenter and Clusters

List all datacenter in a vCenter

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: cf2cc0c3b07bd3a01224f06aa00fea59’ -X GET https://vcentersrv01.alex.local/rest/vcenter/datacenter

Output of above query will contain name of all datacenter that has been created in a vCenter



Details about particular datacenter

You can fetch details like host_folder, network_folder etc for a specific datacenter by using below query. You can use those details in doing scripting for automated deployment of stuffs.

Note: Do not use datacenter name in below query. Use id which you obtained in above step.

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: cf2cc0c3b07bd3a01224f06aa00fea59’ -X GET https://vcentersrv01.alex.local/rest/vcenter/datacenter/datacenter-2






Delete an empty datacenter

You can delete an empty datacenter using below query

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: cf2cc0c3b07bd3a01224f06aa00fea59’ -X DELETE https://vcentersrv01.alex.local/rest/vcenter/datacenter/datacenter-58

If you get Http 200 OK it means query have been executed successfully. You can also verify successful deletion of datacenter from vCenter Web Client.

HTTP/1.1 200 OK
Date: Thu, 15 Dec 2016 18:16:17 GMT
Content-Length: 0

Force removal of datacenter (when datacenter is not empty)

If a datacenter is not empty, you can force delete the contents and datacenter by specifying force=true in the API query

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: cf2cc0c3b07bd3a01224f06aa00fea59′ -X DELETE https://vcentersrv01.alex.local/rest/vcenter/datacenter/datacenter-68?force=true’


Show all cluster in a vCenter

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 4ca9afd3971255748599bc9e47c4f4a1’ -X GET https://vcentersrv01.alex.local/rest/vcenter/cluster

Output of above query will list all clusters present in a vCenter. Also you will get cluster id and details about cluster properties like HA/DRS etc.


List particular Cluster

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 4ca9afd3971255748599bc9e47c4f4a1’ -X GET https://vcentersrv01.alex.local/rest/vcenter/cluster?filter.names=Cybertron

Output will tell you the resource_pool id which is associated with cluster ‘cybertron’


List all cluster in a given Datacenter

If you have multiple virtual datacenters in vcenter and you want to fetch details of all clusters which are in a given datacenter, you can do so by applying a filter with datacenter id in the query.

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 4ca9afd3971255748599bc9e47c4f4a1’ -X GET https://vcentersrv01.alex.local/rest/vcenter/cluster?filter.datacenters=datacenter-2

Details of a particular cluster 

Details of a particular cluster can be fetched using below query.

Note that after /cluster I have given cluster id and not the cluster name. If you specify cluster name here, you will get error that ‘resource do not exist’

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 4ca9afd3971255748599bc9e47c4f4a1’ -X GET


Thats it for this post. This a very basic overview of using API calls. There is a lot to explore and I will try to dive a bit deep in future posts of this series.


About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Vmware. Bookmark the permalink.

2 Responses to Exploring vSphere 6.5 API-Part 1: Datacenter & Cluster

  1. Pingback: Exploring vSphere 6.5 API-Part 2: Virtual Machines | Virtual Reality

  2. Pingback: Exploring vSphere 6.5 API-Part 3: Esxi Host | Virtual Reality

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s