# Getting both Error 300 and Error 400 back when creating a new user with PowerShell against V2 API

**URL:** <https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209>\
**Category:** API and Webhooks\
**Created:** [July 26, 2019, 6:33pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209 "2019-07-26T18:33:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmccrae](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jmccrae/32/1172_2.png) [@jmccrae](https://devforum.zoom.us/u/jmccrae)\
**Post date:** [July 26, 2019, 6:33pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209/1 "2019-07-26T18:33:17Z")

</div>

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](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:…

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 26, 2019, 6:54pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209/2 "2019-07-26T18:54:54Z")

</div>

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?

```json
$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,  
 ![10%20PM](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/2X/4/4093950ed0eff29c300461e96a76fb290d454a6e.png)

Try this,

```json
{
  "action": "create",
  "user_info": {
    "email": "$email",
    "type": "2",
    "first_name": "$firstname",
    "last_name": "$lastname",
    "password": "$defaultpass"
  }
}

```

![20%20PM](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/2X/9/9ff035257355f01bdd42938effa65e72107c47ca.png)

Let me know if this works,  
-Tommy

---

<div class="post-metadata">

**Author:** ![jmccrae](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/jmccrae/32/1172_2.png) [@jmccrae](https://devforum.zoom.us/u/jmccrae)\
**Post date:** [July 26, 2019, 7:24pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209/3 "2019-07-26T19:24:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [July 26, 2019, 7:52pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209/4 "2019-07-26T19:52:30Z")

</div>

You are welcome, glad I was able to help!

Thanks for posting what worked!

-Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 6:36pm UTC](https://devforum.zoom.us/t/getting-both-error-300-and-error-400-back-when-creating-a-new-user-with-powershell-against-v2-api/5209/5 "2020-08-21T18:36:05Z")

</div>

Closed on August 21, 2020, 6:36pm UTC


