"2031 - Zoom Phone has not been enabled for this account" - API Error

I’m trying to test the API to see if I can get call log history but I’m running into an issue. I’ve set up a server-to-server OAuth app to use with the script below.

I’ve given the app the scope “phone:read:list_call_logs:admin”. The documentation also says to give the ones below, but they do not appear in the list of available ones to select.

  • phone:read:admin
  • phone_call_log:read:admin

I just keep getting this error:
{“code”:2031,“message”:“Zoom Phone has not been enabled for this account.”}

The account I’m using to setup the app has the Owner role, and Zoom phone is in fact enabled and working on the account, so I’ve no idea why I’m getting this error message. Can anyone advise?

import requests
import sqlite3
import base64
import time

# OAuth token URL and the new API endpoint for call history
ZOOM_OAUTH_TOKEN_URL = "https://zoom.us/oauth/token"
ZOOM_PHONE_CALL_HISTORY_URL = "https://api.zoom.us/v2/phone/call_history"

# Replace with your Zoom OAuth Client ID and Secret for Server-to-Server OAuth
CLIENT_ID = 'ID'
CLIENT_SECRET = 'SECRET'

# SQLite database setup
DB_FILE = 'zoom_phone_call_logs.db'

def get_zoom_oauth_token():
    """
    Get OAuth token from Zoom API using client credentials for Server-to-Server OAuth.
    """
    auth_header = base64.b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode('utf-8')).decode('utf-8')
    headers = {
        'Authorization': f'Basic {auth_header}',
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    data = {
        'grant_type': 'client_credentials'
    }

    response = requests.post(ZOOM_OAUTH_TOKEN_URL, headers=headers, data=data)

    if response.status_code == 200:
        token_data = response.json()
        return token_data['access_token'], token_data['expires_in']
    else:
        print("Failed to get token:", response.status_code, response.text)
        return None, None

def get_call_history(access_token, from_date, to_date, page_size=100):
    """
    Get account's call history from Zoom Phone API.
    """
    headers = {
        'Authorization': f'Bearer {access_token}'
    }

    params = {
        'from': from_date,
        'to': to_date,
        'page_size': page_size
    }

    all_call_logs = []
    next_page_token = None

    while True:
        if next_page_token:
            params['next_page_token'] = next_page_token

        response = requests.get(ZOOM_PHONE_CALL_HISTORY_URL, headers=headers, params=params)

        if response.status_code == 200:
            data = response.json()
            call_logs = data.get('call_logs', [])
            all_call_logs.extend(call_logs)
            next_page_token = data.get('next_page_token', None)

            if not next_page_token:
                break
        else:
            print("Failed to get call logs:", response.status_code, response.text)
            break

        time.sleep(1)  # To avoid hitting API rate limits

    return all_call_logs

def store_call_logs_in_db(call_logs):
    """
    Store call logs into SQLite database.
    """
    conn = sqlite3.connect(DB_FILE)
    cursor = conn.cursor()

    # Create table if it doesn't exist
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS call_logs (
            call_id TEXT PRIMARY KEY,
            call_type TEXT,
            callee_country_code TEXT,
            callee_country_iso_code TEXT,
            callee_did_number TEXT,
            callee_name TEXT,
            call_start_time TEXT,
            call_end_time TEXT,
            duration INTEGER
        )
    ''')

    # Insert or update call logs
    for log in call_logs:
        cursor.execute('''
            INSERT OR REPLACE INTO call_logs (call_id, call_type, callee_country_code, callee_country_iso_code, callee_did_number, callee_name, call_start_time, call_end_time, duration)
            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
        ''', (
            log['call_id'],
            log.get('call_type', ''),
            log.get('callee_country_code', ''),
            log.get('callee_country_iso_code', ''),
            log.get('callee_did_number', ''),
            log.get('callee_name', ''),
            log.get('call_start_time', ''),
            log.get('call_end_time', ''),
            log.get('duration', 0)
        ))

    conn.commit()
    conn.close()

def main():
    access_token, expires_in = get_zoom_oauth_token()

    if not access_token:
        print("Unable to obtain access token. Exiting.")
        return

    print(f"Access token acquired. Expires in {expires_in} seconds.")

    call_logs = get_call_history(access_token, '2023-09-01', '2023-09-30')
    
    if call_logs:
        print(f"Fetched {len(call_logs)} call logs.")
        store_call_logs_in_db(call_logs)
        print("Call logs stored in database.")
    else:
        print("No call logs found.")

if __name__ == '__main__':
    main()

This ended up because I had grand_type set to ‘client_credentials’ rather than ‘account_credentials’. I also needed to specify ‘account_id’

Thanks for sharing your findings with the Community!

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