Skip to main content
Question

Pull call data python API

  • September 24, 2019
  • 4 replies
  • 2018 views

Hi,

How can I pull the call data in a Python script, I've been able to connect fine however I'm not sure how to deal with pagination?

I'd like to run the script every 15 mins to pull recent calls and not create duplicats, any sample code that you can help me with?

I will then send the JSON data to a MySQL database.

Thanks

4 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • September 24, 2019

Here you are. Run this script every 15 mins or put it in a loop to call every 15 mins.

from ringcentral import SDK
from credentials import *
import time, json
from time import sleep
from datetime import datetime


rcsdk = SDK( RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_SERVER)
platform = rcsdk.platform()
platform.login(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD)

now = time.time()
less15Mins = now - (60 * 1
dateFrom = datetime.utcfromtimestamp(less15Mins).strftime('%Y-%m-%dT%H:%M:%S.000Z'
# use the perPage to control your reading block. max is 1000 items
params = {
    'dateFrom': dateFrom,
    'perPage': 1000
}

resp = platform.get('/restapi/v1.0/account/~/extension/~/call-log', params)
print ((resp.json()))

run = True
while run:
    try:
        nextPage = resp.json().navigation.nextPage
        print (nextPage.uri)
        resp = platform.get(nextPage.uri)
        for record in resp.json().records:
            print ("Call type: " + record.type)
        nextPage = resp.json().navigation.nextPage
        sleep(1.2)
    except:
        print("not found")
        run = False

  • Author
  • New Participant
  • October 7, 2019

Thank you so much!


  • Author
  • New Participant
  • October 7, 2019

I get


dateFrom = datetime.utcfromtimestamp(less15Mins).strftime('%Y-%m-%dT%H:%M:%S.000Z'

^

SyntaxError: invalid syntax


  • Author
  • New Participant
  • October 7, 2019

Hi, unfortunately I just keep getting this error with no luck.

Traceback (most recent call last):

File "C:UsersTPH AdminAppDataLocalProgramsPythonPython37-32libsite-packages ingcentralhttpclient.py", line 28, in send

response.response().raise_for_status()

File "C:UsersTPH AdminAppDataLocalProgramsPythonPython37-32libsite-packages equests-2.21.0-py3.7.egg equestsmodels.py", line 940, in raise_for_status

raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://platform.ringcentral.com//restapi/oauth/token

During handling of the above exception, another exception occurred: