Your example iterates the the json at the top level like this:
for record in resp.json().records:
print "Call type: " + record.type
I am getting an error that the object is not iterable if I try and iterate a nested key with this:
for callfrom in record.from:
How do I iterate the nested keys?
Issue is reserved word "from". Use standard python json object instead of the ringcentral JsonObject as indicated in your answer but you can do this instead:
response = json.loads(resp.text())
for record in response["records"]:
print(f'Call result: {record["result"]} {record["startTime"]} from {record["from"]["phoneNumber"]}')
I figured it out a solution. I can traverse the call log data and get the to and from phone numbers like this:
logdata=resp.text()
dict1 = json.loads(logdata)
for x, y in dict1.items():
if x == 'records':
for item in y:
if isinstance(item,dict):
for a, b in item.items():
if a == 'to':
print('To',b["phoneNumber"])
if a == 'from':
print('From',b["phoneNumber"])
{
"records" : [ {
"id" : "AiQdXSahI0gKzUA",
"sessionId" : "25883985004",
"startTime" : "2021-07-12T18:50:00.581Z",
"duration" : 31,
"type" : "Voice",
"internalType" : "LocalNumber",
"direction" : "Inbound",
"action" : "Phone Call",
"result" : "Missed",
"to" : {
"phoneNumber" : "+14242728375"
},
"from" : {
"phoneNumber" : "+18604281711",
"location" : "Willimantic, CT"
},
"telephonySessionId" : "s-65ac02cc65d84ee195e1fe42d2b0ed24"
}, {
"id" : "AiQdW8NbquqAzUA",
"sessionId" : "25883984004",
"startTime" : "2021-07-12T18:50:00.489Z",
"duration" : 31,
"type" : "Voice",
"internalType" : "LongDistance",
"direction" : "Outbound",
"action" : "RingOut PC",
"result" : "Call connected",
"to" : {
"name" : "Jay Peters",
"phoneNumber" : "+14242728375",
"location" : "Santa Monica Santa Monica, CA"
},
"from" : {
"name" : "Jay Peters",
"phoneNumber" : "+18604281711",
"extensionId" : "299164004"
},
"extension" : {
"uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0/account/299164004/extension/299164004",
"id" : 299164004
},
"telephonySessionId" : "s-9d40efdebaf04bae81b2a8859cef6adf"
} ],
"paging" : {
"page" : 1,
"perPage" : 100,
"pageStart" : 0,
"pageEnd" : 1
},
"navigation" : {
"firstPage" : {
}
}
}
The response is valid and the resp.json().records should be a valid array too. Not sure why you got that error. Can you try with Python 3.x? It shouldn't be a matter but just a test.
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder