jmccrae
(John)
July 26, 2019, 6:33pm
1
I have 2 bits of code in play here. The first creates a Jason Web Token. It works fine. I have a second, working bit of code that can pull back a userlist from our Zoom instance no problem with the JWT code. However, trying to add a new user is throwing weird errors
$token = Get-MyJWT -Algorithm ‘HS256’ -type ‘JWT’ -Issuer -SecretKey -ValidforSeconds 30
$headers = @{“Authorization” = “Bearer $token” }
$body = @"
{
“action”: “create”,
“user_info”: {
“email”: “$email”,
“type”: “2”,
“first_name”: “$firstname”,
“last_name”: “$lastname”,
“password”: “$defaultpass”
}
}
"@ | ConvertFrom-Json
$returncode = Invoke-RestMethod -Headers $headers -Method Post -Uri https://api.zoom.us/v2/users -Body $body -ContentType ‘application/json’
When I run that I get back an error 300. However when I interrogate the $Error object, it says I really got back an error 400 about invalid json body. What am I doing wrong here?
Example output:
Invoke-RestMethod : {“code”:300,“message”:“Request Body should be a valid JSON object.”}
Response : StatusCode: 400, ReasonPhrase: ‘Bad Request’, Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent, Headers:…
tommy
(Tommy Gaessler (PM VDI, Web, Linux, & Meeting SDK))
July 26, 2019, 6:54pm
2
Hey @jmccrae ,
Two thoughts, I am wondering if the quotes around the body object (after the @ are turning the whole object into a string?
Maybe try this?
$body = @
{
"action": "create",
"user_info": {
"email": "$email",
"type": "2",
"first_name": "$firstname",
"last_name": "$lastname",
"password": "$defaultpass"
}
}
@
My other thought (could just be a weird copy/paste thing) the double quotes in your JSON body are not valid JSON quotes.
Example,
Try this,
{
"action": "create",
"user_info": {
"email": "$email",
"type": "2",
"first_name": "$firstname",
"last_name": "$lastname",
"password": "$defaultpass"
}
}
Let me know if this works,
-Tommy
jmccrae
(John)
July 26, 2019, 7:24pm
3
Thanks for the pointer @tommy
Here’s what ultimately worked:
$body = @{
action = "create"
user_info = @{
email = "$email"
type = 2
first_name = "$firstname"
last_name = "$lastname"
password = "$defaultpass"
}
} | ConvertTo-Json
Thanks again, you sent me in the right direction.
tommy
(Tommy Gaessler (PM VDI, Web, Linux, & Meeting SDK))
July 26, 2019, 7:52pm
4
You are welcome, glad I was able to help!
Thanks for posting what worked!
-Tommy