Skip to content

Instantly share code, notes, and snippets.

@prydin
Created September 23, 2026 18:14
Show Gist options
  • Select an option

  • Save prydin/ea22c0954fb369b3bccdc6409c659a4d to your computer and use it in GitHub Desktop.

Select an option

Save prydin/ea22c0954fb369b3bccdc6409c659a4d to your computer and use it in GitHub Desktop.
Simple VFCA Interaction
"""
Simple example: authenticate to VCFA (VMware Cloud Foundation Automation) 9.1
and list the VM App blueprints in a project.
Fill in the constants below and run: python list_blueprints.py
"""
import requests
# --- Configuration ---
VCFA_HOST = "vcfa.example.com" # your VCFA appliance hostname/IP
USERNAME = "administrator"
PASSWORD = "changeme"
DOMAIN = "System Domain" # local/SSO domain
PROJECT_ID = "your-project-id" # project to list blueprints for
BASE_URL = f"https://{VCFA_HOST}"
VERIFY_SSL = False # set to True if using a trusted certificate
if not VERIFY_SSL:
requests.packages.urllib3.disable_warnings()
# 1. Authenticate: get a refresh token from the identity service
login_resp = requests.post(
f"{BASE_URL}/csp/gateway/am/api/login",
json={"username": USERNAME, "password": PASSWORD, "domain": DOMAIN},
verify=VERIFY_SSL,
)
login_resp.raise_for_status()
refresh_token = login_resp.json()["refresh_token"]
# 2. Exchange the refresh token for a bearer access token
token_resp = requests.post(
f"{BASE_URL}/iaas/api/login",
json={"refreshToken": refresh_token},
verify=VERIFY_SSL,
)
token_resp.raise_for_status()
access_token = token_resp.json()["token"]
headers = {"Authorization": f"Bearer {access_token}"}
# 3. List the blueprints (VM Apps) in the project
blueprints_resp = requests.get(
f"{BASE_URL}/blueprint/api/blueprints",
params={"projectId": PROJECT_ID},
headers=headers,
verify=VERIFY_SSL,
)
blueprints_resp.raise_for_status()
for blueprint in blueprints_resp.json().get("content", []):
print(f"{blueprint['name']} (id={blueprint['id']})")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment