Question

Transfer ringcentral call using api

  • 22 April 2024
  • 1 reply
  • 35 views

Hi, I am using @ringcentral/sdk in nextjs project and We have ringcentral widget from where we call people. Now, I want to transfer call to another number using API.


I am using this transfer API:

https://platform.ringcentral.com/restapi/v1.0/account/accountId/telephony/sessions/telephonySessionId/parties/partyId/transfer

When call start I can get the telephonySessionId and partyId from this event:

window.addEventListener("message", (e) => {

const data = e.data;

switch (data.type) {

case "rc-active-call-notify":


On UI, I have created the transfer button and on click I execute transfer call button, in this function first I am getting the latest access_token:


var tokens = await platform.auth().data()

if(!tokens.access_token){

toast.error("You are not loggedIn with ringcentral.", {

duration: 2000,

});

return

}

const url = 'https://platform.ringcentral.com/restapi/oauth/token';

const headers = {

'Content-Type': 'application/x-www-form-urlencoded',

"Authorization": "BasicW344343"

};

const data = {

refresh_token: tokens.refresh_token,

grant_type: 'refresh_token',

client_id: '3343433se',

token: tokens.access_token

};

and then calling transfer call API:

const url = `https://platform.ringcentral.com/restapi/v1.0/account/867677/telephony/sessions/${telephonySessionId}/parties/${partyId}/transfer`;

const headers = {

'accept': 'application/json',

'content-type': 'application/json',

'Authorization': `Bearer ${tokenRes?.data?.access_token}`

};

What issue I am facing:

Sometimes, this transfer call is successful but sometimes not. I am getting these errors:

-- Token Not Found Error: This occurs when calling the refresh token API.

-- 404 Error on Transfer Call API: This sometimes happens during the call transfer.

these two errors, I am getting sometimes. But sometimes it works fine. What can be the issue?

Is it possible that the partyId or telephonySessionId is changing during the call? because I saved the details when call start and maybe that's why getting 404 for that?

Could you help me understand these issues and suggest how to resolve them?



1 reply

Userlevel 1

Don't combine 2 different issues into one question like this. It makes it so hard to identify the issues and solve them.

I take this just for the auth and refresh token issue. And make sure you don't have the issue with the token when you test the transfer.

I don't get what you tried to do with your posted code:

const url = 'https://platform.ringcentral.com/restapi/oauth/token';

const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
"Authorization": "BasicW344343"
};

const data = {
refresh_token: tokens.refresh_token,
grant_type: 'refresh_token',
client_id: '3343433se',
token: tokens.access_token
};

In the first part, you seems to call the SDK platform instance to get the tokens

var tokens = await platform.auth().data()

Then you are off the SDK. Why? And you did not show how you get a new access token by using the refresh token?

If you read the tokens from the platform and save it somewhere and try to use it again. You should set it back to the SDK and call functions to check if the token is still valid or not.

var authData = await platform().auth().data();
await platform().auth().setData(authData);

if (await platform.loggedIn()){
      // still logged in => call API
}else{
   // Not logged in => call login()
}


Reply