Skip to main content

Hello,

I am trying to create an app that downloads our call logs and stores them in an interna database. Right now, I have a sandbox app that calls the Call Log API that has 3 dummy calls that I made myself. I can call them from the API , but when I try to visit the recording content URI of any of the calls, I met with this error:

{
"errorCode": "AGW-401",
"message": "Authorization header is not specified",
"errors": [
{
"errorCode": "AGW-401",
"message": "Authorization header is not specified"
}
]
}

Any idea how I can solve this? I think it may be related to getting an access token? I have read that I need one, but have just been using the SDK to login. See below


from ringcentral import SDK


RINGCENTRAL_CLIENTID = 'my id'
RINGCENTRAL_CLIENTSECRET = 'my secret'
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'

rcsdk = SDK( RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()

JWT_TOKEN = 'my jwt'

try:
platform.login( jwt=JWT_TOKEN )

resp = platform.get('/restapi/v1.0/account/~/extension/~/call-log')
print(resp.text())
except Exception as e:
print ("Unable to authenticate to platform. Check credentials." + str(e))

You wrote that you could read your call log, but you cannot download call recordings. However, you showed only the code where you read the call log?

Any way, here is an example code how to read the call log and download call recordings, provided that you have the call recording and your app has the read call recording.

def read_account_call_log():
path = os.getcwd() + "/recording_content/"
if not os.path.isdir(path):
print("create folder")
try:
os.mkdir(path)
except OSError as e:
print(e)

params = {
'dateFrom': "2023-01-01T00:00:00.000Z",
'dateTo': "2023-03-01T00:00:00.000Z",
'perPage': 1000
}
resp = platform.get('/restapi/v1.0/account/~/call-log', params)
jsonObj = resp.json()

for record in jsonObj.records:
if hasattr(record, 'recording'):
fileName = str(record.recording.id) + ".mp3"
try:
res = platform.get(record.recording.contentUri)
file = open(("%s%s" % (path, fileName)),'wb')
file.write(res.body())
file.close()
print ("Call recording saved in " + fileName)
except ApiException as e:
print (e.getMessage())

Reply