question

Nitesh Giri avatar image
Nitesh Giri asked Phong Vu commented

Javascript SDK returning empty response

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.






sdk
1 |3000

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

1 Answer

Phong Vu avatar image
Phong Vu answered Phong Vu commented

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});
7 comments
1 |3000

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

Nitesh Giri avatar image Nitesh Giri commented ·

it's an object:

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

0 Likes 0 ·
Nitesh Giri avatar image Nitesh Giri Nitesh Giri commented ·

What is the expected format @Phong Vu

0 Likes 0 ·
Nitesh Giri avatar image Nitesh Giri Nitesh Giri commented ·

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.

0 Likes 0 ·
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys