Hey guys, powershell has worked great for me in the past with classic API, but it is giving me fits while trying to use the UAPI for the first time.
I need to script swapping computers between prestage scopes, but this is not available in the classic API.
This is my code so far:
function getAuth()
{
$url = "https://mytenant.jamfcloud.com/uapi/auth/tokens"
$creds = Get-Credential
$call = Invoke-RestMethod -Method Post -Credential $creds -Authentication Basic -Uri $url -ContentType "application/json;charset=UTF-8"
return $call
}
$token = getAuth
$token = $token.token
function apiCall()
{
$url = "https://mytenant.jamfcloud.com/uapi/v1/computer-prestages/4"
$headers = @{
Authorization = "Bearer $token"
}
$api = Invoke-RestMethod -Method Get -Uri $url -Headers $headers -ContentType "application/json;charset=UTF-8"
return $api
}
Same exact thing works fine with bash, but I get errors with powershell....
$api = Invoke-RestMethod -Method Get -Uri $url -Headers $headers ...
~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (Method: GET, Requesu2026PowerShell/6.2.4
}:HttpRequestMessage) [Invoke-RestMethod], HttpResponseException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
basically im passing credentials to get a token, then trying to authenticate with the token. the token seems valid, and I can do a GET for all prestages as opposed to just doing a GET on specific scope. The account I am testing with is a global admin, so I should not have any access restrictions, unless it is a problem with the token (which works on other calls)