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.
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.
- platform.auth().setData({ refresh_token});
it's an object:
platform.auth().setData({ refresh_token: 'token'});
What is the expected format @Phong Vu
I am getting this refresh token from two ways:
- 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)
- 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.
So you never read this quick start, see how the tokens stored in the session and set back from the session.
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.
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()
@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.
- if(platform.loggedIn()){
- 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