Getting information from vCloud Director API by cURL

First we need to get API version from vCloud Director.if you use a domain account instead of system you should change the “system” before administrator.

curl -l --user "system\YourUserName" --request GET https://vCloudDirectorFQDN/api/versions

As shown below, you can see the version info in response. you can use the versions which is deprecated = false .

For the next step you need to generate base64 hash of the username and password.

echo -n YourUserName@system:YourPassword  | base64

Now it’s time to get a token from vCloud Director

curl -k -I --header "Accept: application/*;version=32" --header "Authorization: YourBase64Hash" --request POST https://vCloudDirectorFQDN/api/sessions

Like below you can see the token and x-vCloud-authorization, based on which version you will use, you should include X-VMWARE-VCLOUD-ACCESS-TOKEN also for example in many request for API above version 30.However in our example we don’t need it.Of course the version in below example has been changed but it doesn’t matter .

Here we have an example to retrieve all the ESXi hosts registered in vCloud Director

curl -i -k -H "Accept:application/*;version=30.0" -H "x-vcloud-authorization:YourAuthorizationCodeFromLastStep" -X GET https://vCloudDirectorFQDN/api/admin/extension/hostReferences

For more query you can check here

This article is based on VMware KB 56948

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 1