question

Josh Pesikoff avatar image
Josh Pesikoff asked Phong Vu answered

AGW-401 Error when I click on recording contentURI

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))
authenticationcall logs
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered

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

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys