Discussions
Error when create Dialpad user in powershell
about 1 year ago by Preston Smith
I am getting this error when trying to create a user using PowerShell.
Invoke-WebRequest : { "error": { "code": 400, "errors": [ { "domain": "global", "message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field office_id)", "reason":
"badRequest" } ], "message": "Error parsing ProtoRPC request (Unable to parse request content: Message CombinedContainer is missing required field office_id)" } }
At line:9 char:13
+ $response = Invoke-WebRequest -Uri 'https://dialpad.com/api/v2/users' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Here is the code that I am using with example data. If I comment out the variables, then it works. I have also tried only double quotes in the variables. I think it has something to do with that, but I have not figured it out. Has anyone else encountered this, or am I just doing this incorrectly?
$email = '"[email protected]"'
$firstname = '"first"'
$lastname = '"last"'
$headers=@{}
$headers.Add("accept", "application/json")
$headers.Add("content-type", "application/json")
$headers.Add("authorization", "Bearer mApTLRmyNFMyh7tERZCLasTZMBxeBDYZACd6hF5G8gdmLJjbBKN3HUphxx9NBD5qaMZdurh6Eaw2sxHyZ6NRjaYmjg9UxEEx26x4")
$response = Invoke-WebRequest -Uri 'https://dialpad.com/api/v2/users' -Method POST -Headers $headers -ContentType 'application/json' -Body '{"auto_assign":true,"license":"talk","office_id":123456789,"email":$email,"first_name":$firstname,"last_name":$lastname}'