Academy/VCAP — VCF Automation (3V0-21.25)/Lab: Build API Client with Token Refresh & Async Polling
This lab targets VCF 9.0

Lab: Build API Client with Token Refresh & Async Polling

VCF 9.0Intermediatevcap-advanced⏱ 120 min

Objectives

  • Create Python API client library that handles OAuth2 authentication, token refresh, pagination, rate limiting, and async operation polling.

Prerequisites

VCF lab environment deployed and operational

Lab Environment

Standard VCF lab environment for Advanced VCF 9.0 Automation

Tasks

Task 1 Lab: Build API Client with Token Refresh & Async Polling

Create Python API client library that handles OAuth2 authentication, token refresh, pagination, rate limiting, and async operation polling.

Step 1

Create VCFAutomationClient class with authenticate() method

Step 2

Implement auto token refresh in get_headers()

Step 3

Add api_request() wrapper that handles HTTP 429 with exponential backoff

Step 4

Implement paginate() method for bulk listing

Step 5

Add submit_deployment() method that returns request ID

Step 6

Implement poll_request_status() with 10-minute timeout and 5s poll interval

Step 7

Test with real VCF Automation instance: deploy blueprint, poll until completion

Step 8

Verify token refresh happens at 55-minute mark (before 1hr expiry)

Validation Gate

Check: Verify lab completion

Expected: Lab exercise completed successfully

Common Errors

Not handling API pagination for large result sets
Fix: VCF Automation API returns paginated results (default 20 items per page). Code that reads only the first page misses resources. Implement pagination loop: check totalElements vs current page, request next page until all results collected.
Synchronous polling for long-running operations
Fix: Deployment creation returns a request ID, not the final result. Polling too frequently wastes API calls; too infrequently delays workflow. Implement exponential backoff: poll at 5s, 10s, 20s, 30s intervals. Check request status for 'SUCCESSFUL' or 'FAILED'.
Ignoring API rate limits
Fix: VCF Automation API has rate limits. Rapid sequential calls (e.g., deploying 50 VMs in a loop) may hit rate limits causing HTTP 429 errors. Implement rate limiting in your client: max N requests per minute, with retry-after header respect.

Final Validation

Lab completed successfully

✓ All steps completed → No errors observed

Cleanup / Restore

• Revert to snapshot if needed

Design Reflection (VCDX)

API integration skills demonstrate automation maturity. VCDX designs with programmatic management show scalability beyond UI-driven operations.

⚠ Known Pitfalls (from Community KB)

Ignoring API pagination — your script reports 20 VMs when there are actually 200.
Polling synchronously without backoff — wastes API calls and may trigger rate limiting.
Was this page useful?
Type to search. ↑ ↓ to move, Enter to open, Esc to close.