I'm currently working with the RingCentral API and I'm trying to retrieve logs from extensions for the past week. I have a good understanding of setting up servers and I'm planning to console log the data for now.
I've looked through the RingCentral API documentation and various SDKs, but I haven't found a clear solution for this specific task. Could someone provide a guide or example code on how to retrieve these logs? Any help would be greatly appreciated.
const express = require('express');
const RingCentral = require('@ringcentral/sdk').SDK;
let app = express();
let rcsdk = new RingCentral({
server: "https://platform.ringcentral.com", // Use RingCentral.server.production for production
clientId: "[[ID]]",
clientSecret: "[[SECRET]]"
});
let platform = rcsdk.platform();
console.log('RingCentral SDK initialized.');
async function checkCallLogs() {
console.log('Checking call logs...');
try {
console.log('Logging in...');
await platform.login({ jwt: '[[token]]' }); // Replace with your JWT token
console.log('Logged in.');
console.log('Fetching extension details...');
let extensionResponse = await platform.get('/restapi/v1.0/account/~/extension');
console.log('Extension details fetched.');
let extensions = extensionResponse.json().records;
let extensionId;
for (let extension of extensions) {
if (extension.extensionNumber === '144') {
extensionId = extension.id;
break;
}
}
if (!extensionId) {
console.log('Extension not found.');
return;
}
console.log('Fetching call logs...');
let response = await platform.get(`/restapi/v1.0/account/~/extension/${extensionId}/call-
log`, {
dateFrom: '2023-07-11T00:00:00Z' // One week ago
});
console.log('Call logs fetched.');
let records = response.json().records;
if (records) {
console.log(`Checking ${records.length} call records...`);
records.forEach(record => {
console.log(`Call record:`, record);
});
console.log('Call records checked.');
} else {
console.log('No call records found.');
}
} catch (e) {
console.error('Error:', e);
}
}
// Check for call logs every minute
console.log('Starting call log checks every minute...');
setInterval(checkCallLogs, 20000);
Checking call logs...
Logging in...
Logged in.
Fetching extension details...
Extension details fetched.
Error: TypeError: extensions is not iterable
at Timeout.checkCallLogs [as _onTimeout] (C:\Users\chris\Desktop\qserv\qserver.js:28:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
This is what im experiencing when i run it on my local machine