Calling Call-log API using RingCentral JS SDK
dibyenduroy opened this issue · 2 comments
dibyenduroy commented
Hi Team,
I am using the below function to test the API Call using the JS SDK, what I am getting back in the console log is as below, can you please check my code and let me know what is the issue here.
The response returned by this API is : [object Object]
The response JSON returned by this API is : [object Object]
app.get('/log', function(req, res) {
var authData = rcsdk.platform().auth().data();
rcsdk.platform().auth().setData(authData);
token_json = authData['access_token'] ? JSON.stringify(authData.access_token, null, ' ') : '';
response = token_json;
console.log("Before the/account/~/extension/~/presence");
rcsdk.platform().get('/account/~/extension/~/call-log').then(function(apiResponse){
// If you want the response object
console.log("The response returned by this API is : " + apiResponse.response());
// If you want the response object as JSON
console.log("The response JSON returned by this API is : " + apiResponse.json());
});
console.log("Outside the API Request");
res.render('index', {
authorize_uri: rcsdk.platform().authUrl({
brandId: process.env.RC_APP_BRAND_ID, // optional
redirectUri: process.env.RC_APP_REDIRECT_URL // optional if 1 configured
}),
redirect_uri: process.env.RC_APP_REDIRECT_URL,
token_json: token_json,
dibyendu_roy: response
});
// Render home page with params
});
anilkumarbp commented
Are you getting the below console
logs in the browser:
The response returned by this API is : [object Object]
The response JSON returned by this API is : [object Object]
You would need to convert the JS Object
into a JSON
string using JSON.Stringify() as below:
rcsdk.platform().get('/account/~/extension/~/call-log').then(function(apiResponse){
// If you want the response object as JSON
console.log("The response returned by this API is : " + JSON.stringify(apiResponse.json(), null, 2));
});
dibyenduroy commented
@anilkumarbp thanks, yes that's what was happening, I did not do the conversion. Now I can see the logs. Appreciate your help. Awesome.