Skip to main content
Question

Pull call data python API

  • September 24, 2019
  • 1 reply
  • 1958 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

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

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings