managed/api-examples/python-simple/list-universes.ipynb
First, import the required packages.
Next, specify some important variables:
platform_address: The address of the Yugabyte Platform APIplatform_api_key: The API key used to authenticate with the Platform APIFinally, open a HTTP connection to the Yugabyte Platform API.
import os
import http.client
import json
platform_address = 'localhost:9000'
platform_api_key = os.getenv('YB_API_KEY')
conn = http.client.HTTPConnection(f"{platform_address}")
headers = {
'Content-Type': "application/json",
'X-AUTH-YW-API-TOKEN': f"{platform_api_key}"
}
Make an API call to session endpoint to determine customer UUID.
conn.request("GET", "/api/v1/session_info", headers=headers)
res = conn.getresponse()
data = res.read()
session_info = json.loads(data)
customer_uuid = session_info['customerUUID']
print('Customer UUID:\n%s' % customer_uuid)
Make API call to provider endpoint to list universes.
url = f"/api/v1/customers/{customer_uuid}/universes"
conn.request("GET", url, headers=headers)
res = conn.getresponse()
print(json.dumps(json.load(res), indent=2))