I have some endpoints for a particular software that I'm trying to pass usernums through so that I can automate disabling of accounts when users are no longer with the company. I can query the user and lock the account using single commands like one offs by manually putting in the usernum in the URL. If I try to pass in a usernum, I either get all users back or sometimes I was getting a 404 not found. However, the URI is correct as when I look at the apiParameter.uri value it would be the same as if I passed it manually. Not sure what I am missing.
If I run this it will work fine:
$apiParameters = @{
Headers = @{
Accept = 'application/json'
Authorization = "Bearer $bearerToken"
}
Uri = 'https://hostname/ApiServer/administration/api/users/2789'
WebSession = $session
Method = 'GET'
}
# Accessing the user properties
$adminResponse = Invoke-WebRequest @apiParameters
When I run this command I get all users back. I was also getting a 404 error not found which didn't make since either since the URI was correct when I outputed it to the console. I'm passing the usernum value from a MSSQL database to this section. Not sure if that makes a big difference or not.
foreach ($adUser in $ADResults) {
$apiParameters = @{
Headers = @{
Accept = 'application/json'
Authorization = "Bearer $bearerToken"
}
Uri = "https://hostname/ApiServer/administration/api/users/$($adUser.usernum)"
WebSession = $session
Method = 'GET'
}
Try {
$adResponse = Invoke-WebRequest @apiParameters
} Catch {
if ($_.Exception -eq 'The remote server returned an error: (404) Not Found.') {
# Do other things here
}
}
Here was an example of the URI from the console.
https://hostname/ApiServer/onbase/administration/api/users/2779