My GET command is working as intended and returning the user but the POST command to enroll the user into their Call Factor isn’t working and is returning a “400 BAD REQUEST” Error.
I appreciate any ideas to try here
PowerShell Command
Invoke-RestMethod -Method Post -Uri https://OktaTenant.okta.com/api/v1/users/UserID/factors -Headers @{
“Accept” = “application/json”,
“Content-Type” = “application/json”,
“Authorization” = "SSWS "
} -Body @{
“factorType” = “call”,
“provider” = “OKTA”,
“profile” = @{
“phoneNumber” = “+1-###-###-####”
}
}
Output
VERBOSE: Getting Okta User Account
VERBOSE: GET https://OktaTenant.okta.com/api/v1/users/kyle.test
VERBOSE: Headers {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
“Authorization”: "SSWS "
}
VERBOSE: GET https://OktaTenant.okta.com/api/v1/users/kyle.test with 0-byte payload
VERBOSE: received -1-byte response of content type application/json
VERBOSE: Enrolling User into Okta Call Factor
VERBOSE: POST https://OktaTenant.okta.com/api/v1/users/UserID/factors
VERBOSE: Headers {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
“Authorization”: "SSWS "
}
VERBOSE: Body {
“factorType”: “call”,
“provider”: “OKTA”,
“profile”: {
“phoneNumber”: “+1-###-###-####”
}
}
VERBOSE: POST https://OktaTenant.okta.com/api/v1/users/UserID/factors with -1-byte payload
Error from Output
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At E:\uitl\Prepare-OktaVerify\OktaModule.ps1:42 char:5
+ Invoke-RestMethod @InvokeRestmethodSplat -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand