import os
from thinkplatform.sdk import (
MissingContextError,
StaticTokenCredential,
ThinkPlatformApiError,
ThinkPlatformClient,
TokenAcquisitionError,
)
try:
with ThinkPlatformClient(
base_url=os.environ["THINKPLATFORM_API_BASE_URL"],
credential=StaticTokenCredential(os.environ["THINKPLATFORM_ACCESS_TOKEN"]),
org_id=int(os.environ["THINKPLATFORM_ORG_ID"]),
project_id=int(os.environ["THINKPLATFORM_PROJECT_ID"]),
) as client:
print(len(client.home.pages.list()))
except MissingContextError:
print("Set the required organization and project context.")
except TokenAcquisitionError:
print("Check the credential configuration.")
except ThinkPlatformApiError as exc:
if exc.status_code is None:
print("The API could not be reached.")
else:
print(f"API request failed with HTTP {exc.status_code}.")