question

Arron Voce avatar image
Arron Voce asked ·

Pull call data python API

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

call logpythonjson
1 |1000 characters needed characters left characters exceeded

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

1 Answer

· Write an Answer
Phong Vu avatar image
Phong Vu answered ·

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
5 comments Share
1 |1000 characters needed characters left characters exceeded

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

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

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

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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