# Invoke-WebRequest ; Request Body should be a valid JSON object

**URL:** <https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869>\
**Category:** API and Webhooks\
**Created:** [July 28, 2021, 4:30pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869 "2021-07-28T16:30:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![snimmo](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@snimmo](https://devforum.zoom.us/u/snimmo)\
**Post date:** [July 28, 2021, 4:30pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/1 "2021-07-28T16:30:56Z")

</div>

**Description**  
Using PowerShell, the following JSON formatting works for a create user ;

```
      $CreateZoomUserJSON = "
        {
        'action': 'ssoCreate',
        'user_info':
        {
          'email':'user@domain.com',
          'type':'2',
          'first_name':'Simple',
          'last_name':'Test'
        }
        }
      "
$Body = $CreateZoomUserJSON -replace '''','"'
Invoke-RestMethod "https://api.zoom.us/v2/users" -Headers @{ Authorization = "Bearer $Accesstoken" } -Body ($Body) -Method Post -ContentType 'application/json'

```

However, when attempting the same formatting to provision a phone user, I get the error mentioned in the title;

```
$SetPlan = "
{
   'calling_plans':{
	  'type':'200'
   }
}
  "
  $Body = $SetPlan -replace '''','"'
  Invoke-RestMethod "https://api.zoom.us/v2/phone/users/user@domain.com/calling_plans" -Headers @{ Authorization = "Bearer $Accesstoken" } -Body ($Body) -Method Post -ContentType 'application/json'

```

With the error shown below

**Error**  
Invoke-RestMethod : {“code”:300,“message”:“Request Body should be a valid JSON object.”}  
At line:79 char:3  
+ Invoke-RestMethod "[https://api.zoom.us/v2/phone/users/SimpleTest@ea](https://api.zoom.us/v2/phone/users/SimpleTest@ea) …  
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException  
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

**Which App Type (OAuth / Chatbot / JWT / Webhook)?**  
JWT

**Which Endpoint/s?**  
Shown above in description

**How To Reproduce (If applicable)**  
Steps to reproduce the behavior:  
Attempt the same formatting on Powershell when attempting to assign a calling plan/number/ext.

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [July 29, 2021, 6:39pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/2 "2021-07-29T18:39:07Z")

</div>

Hi @snimmo,

It looks like you might be missing some square brackets `[` `]` — see below:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/1/9/194f3bbc481372f717cf2d7a3659c488637ac18d.png)

Let me know if that resolves the issue.

Thanks!  
Will

---

<div class="post-metadata">

**Author:** ![snimmo](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@snimmo](https://devforum.zoom.us/u/snimmo)\
**Post date:** [July 29, 2021, 7:45pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/3 "2021-07-29T19:45:57Z")

</div>

@will.zoom I tried that and I’m 90% sure it gave me the same error but after the brackets were added now it’s saying it can’t find the user (so hurray it works!).

However, I’m kinda confused on just what I need to do from an API perspective on how I should get a phone user provisioned. More so, what order of events need to occur to assign a user to a site with a calling plan/ext?

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [August 2, 2021, 7:42pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/4 "2021-08-02T19:42:40Z")

</div>

Hi @snimmo,

Once a user has the appropriate plan allocated to their profile and a Zoom Phone License, you should be able to assign them a phone number using this endpoint:

> **[Assign phone number to user - Phone - Zoom API - API Reference](https://marketplace.zoom.us/docs/api-reference/zoom-api/phone/assignphonenumber)**
>
> Use this API to assign a phone number to a user who has already enabled Zoom Phone. For user-level apps, pass the me value instead of the userId paramet...

Thanks,  
Will

---

<div class="post-metadata">

**Author:** ![snimmo](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@snimmo](https://devforum.zoom.us/u/snimmo)\
**Post date:** [August 2, 2021, 10:27pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/5 "2021-08-02T22:27:22Z")

</div>

@will.zoom ,

To make sure I got it (sorry for the slashes, it won’t let me post more than 2 links);

1. Create a user here ; //https://api.zoom.us/v2/users
2. Set a calling plan here ; //https://api.zoom.us/v2/phone/users
3. After getting available numbers at their site, assign them a number ; //https://api.zoom.us/v2/phone/users/SimpleTest@domain.com/phone\_numbers
4. Then set extension here ; //https://api.zoom.us/v2/phone/users

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [August 3, 2021, 5:55pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/6 "2021-08-03T17:55:30Z")

</div>

Hey @snimmo,

That looks good! After you create a user however, make sure you’ve assigned them a Zoom Phone license before step 2. This is applied using the `feature` object from this endpoint:

> **[Update user settings - Users - Zoom API - API Reference](https://marketplace.zoom.us/docs/api-reference/zoom-api/users/usersettingsupdate)**
>
> Update a user's settings. For user-level apps, pass the me value instead of the userId parameter.
> 
> Scopes: user:write:admin, user:writeRate Limit Label:...

Thanks!  
Will

---

<div class="post-metadata">

**Author:** ![snimmo](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@snimmo](https://devforum.zoom.us/u/snimmo)\
**Post date:** [August 4, 2021, 8:06pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/7 "2021-08-04T20:06:13Z")

</div>

@will.zoom , Awesome. I was able to update everything accordingly and get a few test accounts spun up and verified working.

Thank you for the assist!

---

<div class="post-metadata">

**Author:** ![will.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/will.zoom/32/14417_2.png) [@will.zoom](https://devforum.zoom.us/u/will.zoom)\
**Post date:** [August 5, 2021, 5:22pm UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/8 "2021-08-05T17:22:10Z")

</div>

Awesome, glad I could help! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [September 5, 2021, 3:22am UTC](https://devforum.zoom.us/t/invoke-webrequest-request-body-should-be-a-valid-json-object/54869/9 "2021-09-05T03:22:21Z")

</div>

Closed on September 5, 2021, 3:22am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
