Created
May 7, 2023 04:40
-
-
Save jessewolcott/2c72f575f544180cfd83df13555a50f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$AppId = "" | |
$Client_Secret = "" | |
$TokenURL = "" # Example: https://www.example.com/oauth2/token | |
$Hostname = "" # Example: https://www.example.com/ | |
$RequestBasePath = "" # Example: api/config/v1 | |
$APIPath = "" # Example: /users | |
$Body = @{ | |
client_id = $AppId | |
client_secret = $Client_Secret | |
grant_type = "client_credentials" | |
} | |
try { | |
Write-Output "Getting API Auth Token" | |
$TokenRequest = Invoke-WebRequest -Method Post -Uri $TokenURL -ContentType "application/x-www-form-urlencoded" -Body $Body -UseBasicParsing -ErrorAction Stop } | |
catch { Write-Output "Unable to obtain access token, moving on..."} | |
if ($TokenRequest){ | |
$Token = ($tokenRequest.Content | ConvertFrom-Json).access_token | |
$AuthHeader1 = @{ | |
'Content-Type'='application\json' | |
'Authorization'="Bearer $Token" | |
} | |
$URL=($Hostname+$RequestBasePath+$APIPath) | |
$RequestContent = (Invoke-WebRequest -Headers $AuthHeader1 -Uri $URL -Method GET).Content | ConvertFrom-Json | |
} | |
if ($RequestContent){ | |
$RequestContent | Out-gridview | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment