Bad Request (Invalid Client) Error

DM
Dheeraj Mutha
Michaels Inc.

I am using the below script to get the token from the mobicontrol api but it keep giving me Invalid Client error or Bad request. what could be the issue? I am using the correct clientid and secret and my credentials are also correct as I am able to login to the portal. Your help will be highly appreciated.

$MCUsername = "MobiControl username goes here"
$MCPassword = "MobiControl Password goes here"
$MCFQDN = "MobiControl FQDN Goes here"
$ClientID = "MobiControl API Client ID Goes here"
$ClientSecret = "MobiControl Client Secret Goes here"
# You may want to figure out a way to encrypt the Password and the Secret, that's best practice

$IDSecret = $ClientID + ":" + $ClientSecret 
$EncodedIDSecret = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($IDSecret))

$Body = @{}
$Body["grant_type"]="password"
$Body["username"]=$MCUsername
$Body["password"]=$MCPassword

$Header = @{}
$Header["Authorization"] = "Basic " + $EncodedIDSecret

try
{
$response = Invoke-restmethod -Uri  https://$MCFQDN/mobicontrol/api/token -Method POST -Headers $Header -Body $Body
}
catch
{
$($_.Exception.Message)
}

$Token = $response.access_token

Write-Host "My MobiControl API Token is: $Token"
3 years ago
SOTI MobiControl
ANSWERS