Download recorded phonecalls

Hello all !

I have a little problem:

I would like to download recorded phonecalls using python and API but all I can get is a token and after that nothing. Thanks for your help !

Here is my code:

API_KEY = 'xxxxx'
API_SECRET = 'xxxxx'
BASE_URL = 'https://login.mypurecloud.de'  # Replace with Genesys API base URL
#'Content-type': 'application/x-www-form-urlencoded'
# Function to authenticate with Genesys API
def authenticate():
    auth_url = f'{BASE_URL}/oauth/token'
    request_body = {
        'grant_type': 'client_credentials'
    }
    request_headers = {
        'Authorization': "Basic " +
                         base64.b64encode(bytes(f"{API_KEY}:{API_SECRET}", "ISO-8859-1")).decode("ascii"),
        'Content-Type': "application/x-www-form-urlencoded"
    }

    response = requests.post(auth_url,data=request_body, headers=request_headers)
    #print(response.json())
    if response.status_code == 200:
        return response.json()['access_token']
    else:
        raise Exception(f"Failed to authenticate: {response.status_code} - {response.text}")

# Function to fetch phone call details
def fetch_phone_calls(access_token):
    call_url = f'{BASE_URL}/api/v2/userrecordings'
    #call_url = f'{BASE_URL}https://developer.genesys.cloud/api/rest/v2/analytics/#post-api-v2-analytics-conversations-details-query'
    # Replace with the actual call API endpoint
    headers = {
        'Authorization': f'Bearer {access_token}'
    }
    # Add parameters to filter the calls as needed
    params = {
        "interval":"2023-13-05T08:00:00.000Z/2023-16-05T08:00:00.000Z",
        "paging": {
        "pageSize": 300,
        "pageNumber": 1
  }
    }
    response = requests.get(call_url, headers=headers)
    print("call response: ",response.text)
    if response.status_code == 200:
       print("returning response ..")
       return response.json()
 
    else:
       raise Exception(f"Failed to fetch phone calls: {response.status_code} - {response.text}")

Can you share some details about the problem? When you say "after that nothing" do you mean your program is hanging? Can you isolate what line of code is causing it to freeze?

Hello! And thanks for quick reply! It get to this:

response = requests.get(call_url, headers=headers)
    print("call response: ",response.text)
    if response.status_code == 200:
       print("returning response ..")
       return response.json()

And returns nothing. That request.get(call_url, headers=headers) with or without params -option .. gives the same result: nothing. And I have tried different urls also, but in this example I am using "/api/v2/userrecordings" but don't know for sure is it correct one ..

Based on my reading of your code, call_url will be https://login.mypurecloud.de/api/v2/userrecordings, which is not correct. You must use the API server to make requests; these endpoints are documented here: https://developer.genesys.cloud/platform/api/.

You might also consider using the Python SDK as it does most of the heavy lifting for you: https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudpython/.

Hello!

Thanks for you help.

If I have understood API correctly I need Recordingid to download recorded phonecall, right ? So, how can I get all recording ids from time period X - Y ? These recordings are few months old which I am after or does it make a difference ?

Thanks!

Problem is solved. Case closed.

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