KB: HTTPie – quick memo on the usage with VMware products

Here is a quick memo on the usage of HTTPie to connect to VMware products to explore or use the API.

Install

(Ubuntu/Debian)

1sudo apt  install -qy jq
2sudo pip3 install -U httpie

VMware vCenter

1# login
2http POST https://vcsa.vlab.lcl/rest/com/vmware/cis/session --verify=no --session=vcsa -a 'administrator@vsphere.local:VMware1!'
3
4# list VMs
5http https://vcsa65.vlab.lcl/rest/vcenter/vm --verify=no --session=vcsa

VMware vCloud Director

 1# One liner login
 2export VCD_TOKEN=$(http POST https://vcd.vlab.lcl/api/sessions "Accept: application/*+json;version=32.0" --session=vcd --verify=no -a 'administrator@System:VMware1!' -h | grep X-VMWARE-VCLOUD-ACCESS-TOKEN | cut -d' ' -f2)
 3
 4# List VMs
 5http "https://vcd.vlab.lcl/api/query?type=vm" \
 6    "Accept: application/*+json;version=32.0" \
 7    "Authorization: Bearer $VCD_TOKEN"
 8
 9# Filtering
10http "https://vcd.vlab.lcl/api/query?type=vm&filter=isVAppTemplate==false;name==mstr-rm7c" \
11    "Accept: application/*+json;version=32.0" \
12    "Authorization: Bearer $VCD_TOKEN"
13
14# Change tenant context
15http "https://vcd.vlab.lcl/api/query?type=vm&filter=isVAppTemplate==false;name==mstr-rm7c" \
16    "Accept: application/*+json;version=32.0" \
17    "X-VMWARE-VCLOUD-TENANT-CONTEXT: <org id>" \
18    "Authorization: Bearer $VCD_TOKEN"

NSX-V

NSX-V API requires basic-auth but does not provide a specific endpoint to create a session. Nevermind you can use the following command to create a HTTPie session, named nsx, and test it.

Then other API call will not require the authentication credentials (just the mention of the session to use).

1# login
2http https://nsxmgr.vlab.lcl/api/2.0/services/usermgmt/user/admin --session=nsx -a 'admin:VMware1!'
3
4# Show DFW config
5http https://nsxmgr.vlab.lcl/api/4.0/firewall/globalroot-0/config "Accept: application/json" --session=nsx