News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Javascript SDK returning empty response
Tags: sdk
Jun 30, 2021 at 10:19am   •   1 replies  •  0 likes
Nitesh Giri

I am following steps as:

1. Create platform object and sign in to platform using oauth code obtained:

const { SDK } = require('@ringcentral/sdk');

const rcsdk = new SDK({
server: 'https://platform.devtest.ringcentral.com/',
clientId: '',
clientSecret: ''});

const platform = rcsdk.platform();
platform.login({code, redirect_uri});

We store the refresh token obtained from login. Platform is destroyed.

2. Use refresh token obtained above to log in to platform and use Ringcentral APIs. For example, I am trying to access extension information here:

const { SDK } = require('@ringcentral/sdk');

const rcsdk = new SDK({
server: 'https://platform.devtest.ringcentral.com/',
clientId: '',
clientSecret: ''});

const platform = rcsdk.platform();
platform.auth().setData({ refresh_token});
const resposne = platform.get('/restapi/v1.0/account/~/extension');
// response is empty 

const newAuthData = platform.auth().data();
// save newAuthData so that when platform is destroyed we can use refresh token
// I have made sure that tokens are managed properly (checking they are expired and if needed refreshing as well)

The problem here is that fetching resources by SDK are returning empty response, i.e though its 200 OK, I am not getting anything in response. I tried fetching call logs etc. and the issue is same for all cases.

One thing to note here is that using APIs via postman with access tokens obtained through SDK work fine and I am able to get a proper response.






1 Answer
answered on Jun 30, 2021 at 11:42am  

What is inside the "refresh_tokens" passed to this function within a { }? Where do you get it? Is it a string or a JSOn object? I am sure that that is the invalid one.

  1. platform.auth().setData({ refresh_token});

 0
on Jun 30, 2021 at 7:09pm   •  0 likes

it's an object:

platform.auth().setData({ refresh_token: 'token'});

on Jun 30, 2021 at 7:11pm   •  0 likes

What is the expected format @Phong Vu

on Jun 30, 2021 at 7:45pm   •  0 likes

I am getting this refresh token from two ways:

  1. when I login using oauth code, it returns me a refresh token (this is for first time only when client logs in to the application, we store it)
  2. For subsequent app runs I have to create a platform object, which is done by refresh token either obtained by login(point 1) or using platform.refresh()

Note: In my use case, platform is destroyed multiple times in a day. It's used by a scheduler which runs at an interval(multiple times in a day).So, each time scheduler runs my application, first I refresh the token(& save it for next run) and then start fetching resources.

on Jun 30, 2021 at 8:52pm   •  0 likes

So you never read this quick start, see how the tokens stored in the session and set back from the session.

on Jul 1, 2021 at 5:10am   •  0 likes

Also, the invocation of these endpoints is not through any http call. I run a script and that in turn fetches saved tokens and inititalize the platform object as I have mentioned above.

on Jul 1, 2021 at 7:03am   •  0 likes

You said you've gone thru. Here is what I saw on the example and not on your code?

var resp = await platform.get(endpoint, params)
var jsonObj = await resp.json()
on Jul 1, 2021 at 1:07am   •  0 likes

@Phong Vu have gone through that.

I believe I am setting tokens properly, because I can refresh the token by calling platform.refresh(). Also platform.loggedIn() returns true for me.

  1. if(platform.loggedIn()){
  2. const resposne = platform.get('/restapi/v1.0/account/~/extension');}

As I mentioned, there are no auth errors or some other errors. Tried to debug going into lib also - receive 200 Ok reponse. It's just I am not getting any data in respose.



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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us