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

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 …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 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.

Hi @snimmo,

It looks like you might be missing some square brackets [ ] — see below:
image

Let me know if that resolves the issue.

Thanks!
Will

@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?

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:

Thanks,
Will

@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

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:

Thanks!
Will

1 Like

@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!

Awesome, glad I could help! :slight_smile:

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