Extending vCloud API with vCloud Extensibility Framework : Command-Line API Calls : 2.1 Log in to vCloud Director API using HTTPie
   
2.1 Log in to vCloud Director API using HTTPie
You must be logged in as a system administrator. This example uses a local system administrator account called api-user.
# http --verify no --session=vcloud-gcp-admin -a api-user@System POST https://vcd.gcp.local/api/sessions 'Accept:application/*+xml;version=5.6'
This example uses a self-signed certificate on a vCloud Director instance, so the –verify no option is passed. After you log in, the session is stored in vcloud-gcp-admin to reuse on future requests.
The output resulting from execution of the example should look something like the following:
HTTP/1.1 200 OK
Content-Length: 1390
Content-Type: application/vnd.vmware.vcloud.session+xml;version=5.6
Date: Tue, 08 Dec 2015 19:49:08 GMT
Date: Tue, 08 Dec 2015 19:49:09 GMT
Set-Cookie: vcloud-token=304715fbb28e4ad19efeb6adfe850184; Secure; Path=/
X-VMWARE-VCLOUD-REQUEST-EXECUTION-TIME: 1076
X-VMWARE-VCLOUD-REQUEST-ID: b64552a4-054a-42e4-9ae1-0ea7fabb56a4
x-vcloud-authorization: 304715fbb28e4ad19efeb6adfe850184
 
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Session xmlns:ns0="http://www.vmware.com/vcloud/v1.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" href="https://vcd.gcp.local/api/session" org="System" type="application/vnd.vmware.vcloud.session+xml" user="api-user" userId="urn:vcloud:user:44fbd6f9-7a76-4bca-b273-3536b181ad09" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcd.gcp.local/api/v1.5/schema/master.xsd">
<ns0:Link href="https://vcd.gcp.local/api/org/" rel="down" type="application/vnd.vmware.vcloud.orgList+xml" />
<ns0:Link href="https://vcd.gcp.local/api/session" rel="remove" />
<ns0:Link href="https://vcd.gcp.local/api/admin/" rel="down" type="application/vnd.vmware.admin.vcloud+xml" />
<ns0:Link href="https://vcd.gcp.local/api/admin/extension" rel="down" type="application/vnd.vmware.admin.vmwExtension+xml" />
<ns0:Link href="https://vcd.gcp.local/api/org/a93c9db9-7471-3192-8d09-a8f7eeda85f9" name="System" rel="down" type="application/vnd.vmware.vcloud.org+xml" />
<ns0:Link href="https://vcd.gcp.local/api/query" rel="down" type="application/vnd.vmware.vcloud.query.queryList+xml" />
<ns0:Link href="https://vcd.gcp.local/api/entity/" rel="entityResolver" type="application/vnd.vmware.vcloud.entity+xml" />
<ns0:Link href="https://vcd.gcp.local/api/extensibility" rel="down:extensibility" type="application/vnd.vmware.vcloud.apiextensibility+xml" />
</ns0:Session>
 
To reuse the session, simply specify the --session=vcloud-gcp-admin parameter on all future calls.
The following example lists all organizations in the vCloud Director instance:
# http --verify no --session=vcloud-gcp-admin --pretty colors GET https://vcd.gcp.local/api/org/
Returns:
<?xml version="1.0" encoding="UTF-8"?>
<OrgList xmlns="http://www.vmware.com/vcloud/v1.5" href="https://vcd.gcp.local/api/org/" type="application/vnd.vmware.vcloud.orgList+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcd.gcp.local/api/v1.5/schema/master.xsd">
<Org href="https://vcd.gcp.local/api/org/a93c9db9-7471-3192-8d09-a8f7eeda85f9" name="System" type="application/vnd.vmware.vcloud.org+xml"/>
<Org href="https://vcd.gcp.local/api/org/9aee51e8-654e-49a8-8dab-3fdbf00a21ae" name="Coke" type="application/vnd.vmware.vcloud.org+xml"/>
<Org href="https://vcd.gcp.local/api/org/2ce0365d-4d7d-4c15-a603-9257ea338c99" name="Pepsi" type="application/vnd.vmware.vcloud.org+xml"/>
</OrgList>