Arron Voce avatar image
Arron Voce asked Arron Voce commented

Pull call data python API


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.


call 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 Arron Voce commented

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

platform = rcsdk.platform()

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:
        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
        print("not found")
        run = False
1 |3000

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

Arron Voce avatar image Arron Voce commented ·

I just keep getting the error

<ringcentral.http.json_object.JsonObject object at 0x02C29DD0>

not found

[Finished in 0.877s]

Any ideas?

Thanks :)

0 Likes 0 ·
Phong Vu avatar image Phong Vu ♦♦ Arron Voce commented ·

Which meant that you don't have more than 1 page.

Replace the code below to see the content.

//print ((resp.json())) 
print ((resp.text())) 

0 Likes 0 ·
Arron Voce avatar image Arron Voce Phong Vu ♦♦ commented ·

Thanks, I tried this and that works but only for the first page.

But when I set

dateFrom = datetime.utcfromtimestamp(less15Mins).strftime('2018-09-06T00:00:00Z')

I still get the error with resp.json and I have hundreds of pages, what am I doing wrong?

Thanks for your help :)

0 Likes 0 ·
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