Greetings...
I'm working on making a rest api call which pulls back data from the year 2000 until the current year when I run the powershell script from my machine everything works as expected. If I were to run the azure automation runbook I get out of memory exception is there anything I should be doing to make this work. I'm looping on this rest endpoint for each year starting from the year 2000.
PoSh:
try {
$clientSecret = ''
$clientId = ''
$tenantId = ''
# Construct URI
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
# Construct Body
$body = @{
client_id = $clientId
client_secret = $clientSecret
scope = 'https://graph.microsoft.com/.default'
grant_type = 'client_credentials'
}
$Year = "2000"
$Uri = "https://apiserver.com/v1/data/year/$Year"
# Get OAuth 2.0 Token
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType 'application/x-www-form-urlencoded' -Body $body -UseBasicParsing
# Access Token
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
$api = Invoke-RestMethod -Method Get -Uri $Uri -ContentType 'application/json' -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop
}
catch {
"Error"
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Write-Host "ErrorMessage:" $_.ErrorDetails.Message
}
Error:
Thank you!!!