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}")