Working with APIs
The Report That Automated Itself
$org = "mycompany"
$project = "MainApp"
$pat = $env:AZDO_PAT
$headers = @{
Authorization = "Basic $([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat")))"
}
$builds = Invoke-RestMethod -Uri "https://dev.azure.com/$org/$project/_apis/build/builds?api-version=7.0" -Headers $headers
$builds.value | Select-Object id, buildNumber, status, result | Export-Csv "builds.csv"Invoke-RestMethod: Your API Swiss Army Knife
Basic GET Request
HTTP Methods
Authentication
Bearer Token
Basic Authentication
API Key
Working with JSON
Parsing JSON Responses
Sending JSON Data
Nested JSON
Real-World API Examples
GitHub API Integration
Azure DevOps API
REST API with Pagination
POST with File Upload
Invoke-WebRequest: When You Need More Control
Downloading Files
Error Handling for API Calls
Rate Limiting
Real-World Integration: Automated Monitoring
Common Pitfalls
1. Not Handling Rate Limits
2. Hardcoded Credentials
3. Not Checking HTTP Status Codes
Key Takeaways
What You've Learned
Next Steps
Last updated