PS Integration with third-party APIs

This script interacts with a REST API by sending an authenticated GET request, processes the API response, and displays the received data.

# Interact with a REST API to retrieve data
$ApiUrl = “https://api.johnzuh.com/data”
$headers = @{
“Authorization” = “Bearer YourAuthToken”
}
$response = Invoke-RestMethod -Uri $ApiUrl -Headers $headers -Method
Get
#Process the response data
if ($response.StatusCode -eq 200) {
$data = $response | ConvertFrom-Json
Write-Host “Received data from the API:”
$data | Format-Table}
else {
Write-Host “Failed to retrieve data from the API. Status code: $($response.StatusCode)
}

Leave a Reply