How can I download call log between two defined date using python or Js

  • 1
  • Question
  • Updated 10 months ago
  • Answered
Hi, I have my APP_KEY, APP_SECRET, USERNAME, PASSWORD.
I have also a little knowledge of python. I want to download detail call log without fax and Inbound calls between two defined date.
Any idea or sample script will be very helpful for me.
Thanks
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb

Posted 10 months ago

  • 1
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
When making a call to the call-log end point, set the following query parameters:

  • dateFrom
  • dateTo
  • direction = 'Outbound'
  • type = 'Voice'
  • view = 'Detailed'

See this example in Python here:

https://github.com/grokify/ringcentral-python-examples/blob/master/demo_call-log.py
(Edited)
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Hi Sir, 
Thanks for your help with the code, I have tried but getting an error, Actually I am confused where I need to put my login details and secret keys etc. Here I have added my code and error found. 
Thanks

Here is my code sample:

import os
from dotenv import load_dotenv
load_dotenv(dotenv_path=os.getenv('ENV_PATH'))

from ringcentral import SDK

sdk = SDK(
os.getenv('MyClientId'),
os.getenv('Mysecret Key'),
os.getenv('https://platform.devtest.ringcentral.com'))

platform = sdk.platform()
platform.login(
os.getenv('MyUsername'),
os.getenv('MyExtention'),
os.getenv('MyPassword'))


try:
from urllib import urlencode
except: # For Python 3
from urllib.parse import urlencode

query = {
'dateFrom': '2018-05-01T00:00:00Z',
'dateTo': '2018-06-01T00:00:00Z',
'direction': 'Outbound',
'type': 'Voice',
'view': 'Detailed'}

qs = urlencode(query)

res = platform.get('/restapi/v1.0/account/~/extension/~/call-log?'+qs)
print(res.text())

Here is the error: 
Traceback (most recent call last):
  File "C:/Python34/Ringcentral.py", line 20, in <module>
    os.getenv('MyPassword'))
  File "C:\Python34\lib\site-packages\ringcentral\platform\platform.py", line 105, in login
    raise e
  File "C:\Python34\lib\site-packages\ringcentral\platform\platform.py", line 82, in login
    raise Exception('Either code or username with password has to be provided')
Exception: Either code or username with password has to be provided
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
Exception: Either code or username with password has to be provided

The reason you are seeing this error is because of how the code is accepting user credentials. You have two basic options here:

  1. Use an external .env file to hold your credentials and reference the file using an environment variable
  2. Hard code your credentials in to the code and removing the os.getenv function calls (which go to the environment)
The script is using approach 1 but it looks like you are attempting to use approach 2 so we need to make one or the other work. Here are ways to make each work with the script.

Approach 1: Using .env Files

Using external .env files is one recommended approach for storing credentials because it keeps them out of your code which often lives in a source control system and can be seen by many people. To do this, create a text file in the same directory as the `demo_call-log.py` script. You can place this anywhere, but we'll start with the same directory. The file should have the following content:

RINGCENTRAL_CLIENT_ID=MyClientId
RINGCENTRAL_CLIENT_SECRET=Mysecret Key
RINGCENTRAL_SERVER_URL=https://platform.devtest.ringcentral.com
RINGCENTRAL_USERNAME=MyUsername
RINGCENTRAL_EXTENSION=MyExtension
RINGCENTRAL_PASSWORD=MyPassword
You can also set the environment variable like the following. Adjust the path as appropriate

Windows:

C:\> setx ENV_PATH "%USERPROFILE%\.credentials\.env"

Linux, Unix, OS X

$ export ENV_PATH=$HOME/.credentials/.env

Approach 2 Hardcoding Credentials

You can hard code your credentials as shown, but you need to remove the `os.getenv` call because that takes an environment variable name and returns it's value. Here you don't want to be calling the environment, so modify the Python code as shown below. You can also remove the dependencies that are no longer used like dotenv and os.

sdk = SDK(
    'MyClientId',
    'Mysecret Key',
    'https://platform.devtest.ringcentral.com')
platform = sdk.platform()
platform.login(
    'MyUsername',
    'MyExtention',
    'MyPassword')
(Edited)
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Hi,
Tanks a lot for spending time for me sir,
I have followed  Approach 2   and seems like it's  working but I am getting another error - "ringcentral.http.api_exception.ApiException: Unauthorized for this grant type"

Can you please tell me the easiest way to solve this issue sir?
Many thanks
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
This type of script is using the Password Grant Type which you need to configure for your app in the Developer Portal. See my answer on this Stack Overflow question about how to configure this:

https://stackoverflow.com/questions/47692828/ringcentral-auth-token-failed-in-curl-call-unauthorized...
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
HI, 
Thanks for all your help. It's now working but giving me empty records. Although I have  lot of calls.

Here is the final code:

from ringcentral import SDK

sdk = SDK(
'xxxxx',
'xxxxxxxxxxxxx',
'https://platform.devtest.ringcentral.com')
platform = sdk.platform()
platform.login(
'xxxxxx',
'xxx',
'xxxxxxxx')


try:
from urllib import urlencode
except:
from urllib.parse import urlencode

query = {
'dateFrom': '2017-06-10T00:00:00Z',
'dateTo': '2018-06-10T00:00:00Z',
'direction': 'Outbound',
'type': 'Voice',
'view': 'Detailed'
}

qs = urlencode(query)

res = platform.get('/restapi/v1.0/account/~/extension/~/call-log?'+qs)
print(res.text()) And I am getting this response" { "uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0/account/242724004/extension/242724004/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2017-06-10T00:00:00.000Z&dateTo=2018-06-10T00:00:00.000Z&page=1&perPage=100", "records" : [ ], "paging" : { "page" : 1, "perPage" : 100 }, "navigation" : { "firstPage" : { "uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0/account/242724004/extension/242724004/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2017-06-10T00:00:00.000Z&dateTo=2018-06-10T00:00:00.000Z&page=1&perPage=100" }, "lastPage" : { "uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0/account/242724004/extension/242724004/call-log?view=Simple&showBlocked=true&withRecording=false&dateFrom=2017-06-10T00:00:00.000Z&dateTo=2018-06-10T00:00:00.000Z&page=1&perPage=100" } } }
(Edited)
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
It's now working but giving me empty records. Although I have  lot of calls.
Does the user you are making the API call with have any calls?

When calling the "extension/call-log" endpoint, records are returned specifically for the extension that authorized the app:

/restapi/v1.0/account/~/extension/~/call-log

To get records for all users in the account, use the "account/call-log" endpoint:

/restapi/v1.0/account/~/call-log
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Yes sir, User have a lot of calls?
I am now using 
/restapi/v1.0/account/~/call-log
But it still giving Empty records as previous.
(Edited)
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
Could the issue be you are currently making API calls to the sandbox account and your calls are in your production account?

You are currently making API calls against your sandbox account:
When you log into the associated Online Account Portal account (note the .devtest) in the host name, do you see calls in the Call Log report?

To make some calls in the sandbox, you can reset your RingCentral for Desktop softphone to log into your sandbox account and make/receive calls. More information is available on this here:
If you are trying to see calls you made in your production account, you will need to graduate your app and then update your app and user credentials.
(Edited)
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Hello Sir,
You are awesome...!
I have updated my app to Production and it's working perfectly for call log now.
I have created another app for reading meeting list And getting this error bellow.
Although I have set permission for Meetings.


{ "errorCode": "CMN-408", "message": "In order to call this API endpoint, user needs to have [Meetings] permission for requested resource.", "errors": [ { "errorCode": "CMN-408", "message": "In order to call this API endpoint, user needs to have [Meetings] permission for requested resource.", "permissionName": "Meetings" } ], "permissionName": "Meetings" }
(Edited)
Photo of John Wang

John Wang, Official Rep

  • 5,786 Points 5k badge 2x thumb
RingCentral has two sets of permissions, app permissions and user permissions. This specific error says "user needs" so this is a user permission. To verify the user you are using has this permission, go to the Online Account Portal:

* Sandbox: https://service.devtest.ringcentral.com
* Production: https://service.ringcentral.com

Go to "Users" > "Roles" and ensure the user that authorized the app has the "Meetings App Access" permission.

https://success.ringcentral.com/articles/RC_Knowledge_Article/5-10-Editing-the-Extension-Permissions...

Here's what the permission looks like in the UI:
I posted a bit more on this here:

https://stackoverflow.com/questions/50977970/ringcentral-meetings-api-error-user-needs-to-have-meeti...
(Edited)
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Hi, Thanks a lot for helping me sir.
Now it's working perfectly.
Thanks you very much sir.
One more question sir- Can i change time zone while making API call like GMT-7? As Timestamp logged in RingCentral is GTM time.

Many Thanks
Photo of Atik R

Atik R

  • 168 Points 100 badge 2x thumb
Hi, Thanks Problem solve....!