question

atik-r10593 avatar image
atik-r10593 asked atik-r10593 commented

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

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

getting started
1 |3000

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

John Wang avatar image
John Wang Deactivated answered
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
1 |3000

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

atik-r10593 avatar image
atik-r10593 answered atik-r10593 commented
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
11 comments
1 |3000

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

John Wang avatar image John Wang ♦♦ commented ·
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')
1 Like 1 ·
John Wang avatar image John Wang ♦♦ commented ·
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...
1 Like 1 ·
John Wang avatar image John Wang ♦♦ commented ·
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
1 Like 1 ·
John Wang avatar image John Wang ♦♦ commented ·
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.
1 Like 1 ·
John Wang avatar image John Wang ♦♦ commented ·

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://support.ringcentral.com/article/5-10-Editing-the-Extension-Permissions-via-Web.html


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...

1 Like 1 ·
Show more comments

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