Zoom Phone: Change User Extension by API

I am trying to use the API to update a zoom phone user’s extension.

In this API Zoom Phone API | Zoom Developer Docs

Under Users → Update user’s profile → extension_number

When I try to update the extension it gives an error code back of 200. The response message is blank and the value does not get updated.

I also tried updating other fields in the user profile and they will not update either. I can not get it to return any other response code other then 200.

Can anyone see if you can duplicate this issue on your side?

I am using Python 3 and pyjwt request.
This is my code:

def changeExtension(email, extension):
id = getUserID(email)
if id:
settings = {‘extension_number’: extension}
url = ‘https://api.zoom.us/v2/phones/users/’ + id
r = requests.patch(url, headers=API_HEADERS, data=json.dumps(settings))

Thanks!

Hi @dupination

I just tried out the API endpoint and was able to make the change.

Here is my question to you:

  1. Does it work when you try making the operation from Postman?

  2. If No, then What token are you using to make the API call (JWT / OAuth), sometimes JWT token dosen’t work right with Zoom Phone APIs?

Here is a sample request that worked for me:

import requests
import json

url = "https://api.zoom.us/v2/phone/users/userID"

payload = json.dumps({
  "extension_number": "981"
})
headers = {
  'Authorization': 'Bearer Token',
  'Content-Type': 'application/json'
}

response = requests.request("PATCH", url, headers=headers, data=payload)

print(response.text)

Hey @Ojus

Thanks for taking a look and the code snip.
To answer your questions:

  1. No
  2. I am using JWT.

Our use case for using the API is to maintain and provision our users for Zoom Phone migration. After reading the OAuth documentation, I don’t believe it fits our needs since we just need system access.

Are you able to try using a JWT token to modify the extension of a user?

Here is my code:

#!/usr/bin/env python3
# provision_zoom_phone_users.py

# API
# Zoom: https://marketplace.zoom.us/docs/api-reference/phone/methods

import math
from textwrap import indent
from unittest.mock import patch
from wsgiref.util import setup_testing_defaults
from requests import get
import jwt
import requests
import json
import urllib3
from time import time


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# TEST API key and API secret
API_KEY = 'YOUR_KEY'
API_SEC = 'YOUR_SEC'

# GLOBALS
LIMIT = 300
NEXT_TOKEN = ''

#############################################

def main_request(baseurl, parm_name1, parm_value1, parm_name2, parm_value2):
    parameters = {
        parm_name1: parm_value1, 
        parm_name2: parm_value2
        }
    data = requests.get(baseurl, headers=API_HEADERS, params=parameters, verify=False).json()
    global NEXT_TOKEN
    NEXT_TOKEN = data['next_page_token']
    return data

def parse_json(response, field_name, dict_name):
    datalist = []
    for item in response[dict_name]:
        if field_name in item:
            item_list = {
                'id': item['id'],
                field_name: item[field_name]
            }
            datalist.append(item_list)
    return datalist    

def get_pages(response):
    return math.ceil(response['total_records']/LIMIT)
    
def getZoomToken():
    # Generate a token
    # using the pyjwt library
    token = jwt.encode({'iss': API_KEY, 'exp': time() + 5000},API_SEC,algorithm='HS256')
    headers = {'authorization': 'Bearer %s' % token,'content-type': 'application/json'}
    return headers

def getAllIDs(url, field, dict_name):
    parsed_data = []
    global NEXT_TOKEN

    # First call to get page numbers then reset page token
    NEXT_TOKEN = ''
    data = main_request(url, '', '', 'next_page_token', NEXT_TOKEN)
    NEXT_TOKEN = ''
    for x in range(1,get_pages(data)+1):
        parsed_data.extend(
            parse_json(
                main_request(url, '', '', 'next_page_token', NEXT_TOKEN),
                field,
                dict_name
            ))

    return parsed_data


#############################################


def getAllUserIDs():
    return getAllIDs("https://api.zoom.us/v2/users?page_size="+str(LIMIT), 'email', 'users')
      
def getUserID(email):
    for i in USER_IDS:
        if i['email'] == email:
            return i['id']

def changeExtension(email, extension):
    id = getUserID(email)
    if id:
        settings = {'extension_number': extension}
        API_PATCH_URL = 'https://api.zoom.us/v2/phones/users/' + id 
        r = requests.post(API_PATCH_URL, headers=API_HEADERS, data=json.dumps(settings))
        print(r.status_code)
        print(r.text)                                        

API_HEADERS = getZoomToken()
USER_IDS = getAllUserIDs()


changeExtension("YOUR_EMAIL", '96666')


Thanks in advance!
Ryan