# Zoom Phone: Change User Extension by API

**URL:** <https://devforum.zoom.us/t/zoom-phone-change-user-extension-by-api/65174>\
**Category:** Phone\
**Created:** [March 3, 2022, 2:07pm UTC](https://devforum.zoom.us/t/zoom-phone-change-user-extension-by-api/65174 "2022-03-03T14:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dupination](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dupination/32/35614_2.png) [@dupination](https://devforum.zoom.us/u/dupination)\
**Post date:** [March 3, 2022, 2:07pm UTC](https://devforum.zoom.us/t/zoom-phone-change-user-extension-by-api/65174/1 "2022-03-03T14:07:46Z")

</div>

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

In this API [Zoom Phone API | Zoom Developer Docs](https://marketplace.zoom.us/docs/api-reference/phone/methods/#operation/updateUserProfile)

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/](https://api.zoom.us/v2/phones/users/)’ + id  
r = requests.patch(url, headers=API\_HEADERS, data=json.dumps(settings))

Thanks!

---

<div class="post-metadata">

**Author:** ![ojus.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ojus.zoom/32/734_2.png) [@ojus.zoom](https://devforum.zoom.us/u/ojus.zoom)\
**Post date:** [March 4, 2022, 10:09pm UTC](https://devforum.zoom.us/t/zoom-phone-change-user-extension-by-api/65174/2 "2022-03-04T22:09:34Z")

</div>

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:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![dupination](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/dupination/32/35614_2.png) [@dupination](https://devforum.zoom.us/u/dupination)\
**Post date:** [March 7, 2022, 6:22pm UTC](https://devforum.zoom.us/t/zoom-phone-change-user-extension-by-api/65174/3 "2022-03-07T18:22:28Z")

</div>

Hey @ojus.zoom

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:

```auto
#!/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
