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

Hi everyone,

I’m trying to get the call log from my organization’s account. I do have the necessary permissions.

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

On the thread 117278 (it didnt give me permission to include the link), an user gave me an alternative code that would work pretty well for me:

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()

The original user mentioned that to fix it, he had to set grant_type set to ‘client_credentials’ rather than ‘account_credentials’ and specify ‘account_id

However, I’m having some trouble making those edits.

Could someone please advise me?

Thank you so much!

Hey @Vitor1
Thanks for reaching out to us
You should not be using “client_credentials” as a grant type, if you are working with S2S oauth app, the grant_type is “account_credentials”

Could you please change the grant type and try again?

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