Enroll Call Factor API

PowerShell Command

Invoke-RestMethod -Method Post -Uri https://$tenantHere.okta.com/api/v1/users/$UserID/factors -Headers @{
“Accept” = “application/json”,
“Content-Type” = “application/json”,
“Authorization” = “SSWS $APIKey”
} -Body @{
“factorType” = “call”,
“provider” = “OKTA”,
“profile” = @{
“phoneNumber” = “+1-###-###-####”
}
}

Output

This GET API Call works

VERBOSE: Getting Okta User Account
VERBOSE: GET https://$tenantHere.okta.com/api/v1/users/kyle.test
VERBOSE: Headers {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
“Authorization”: “SSWS $APIKey”
}
VERBOSE: GET https://$tenantHere.okta.com/api/v1/users/kyle.test with 0-byte payload
VERBOSE: received -1-byte response of content type application/json

This POST API Call is failing

VERBOSE: Enrolling User into Okta Call Factor
VERBOSE: POST https://$tenantHere.okta.com/api/v1/users/$UserID/factors
VERBOSE: Headers {
“Accept”: “application/json”,
“Content-Type”: “application/json”,
“Authorization”: “SSWS $APIKey”
}
VERBOSE: Body {
“factorType”: “call”,
“provider”: “OKTA”,
“profile”: {
“phoneNumber”: “+1-###-###-####”
}
}
VERBOSE: POST https://$tenantHere.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 L:\Share\FolderName\OktaModule.ps1:42 char:5
Invoke-RestMethod @InvokeRestmethodSplat -Verbose
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand