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
Transfer ringcentral call using api
Tags: rest api, transferring calls, call transfer, get token
Apr 22, 2024 at 12:12am   •   1 replies  •  0 likes
SARFEZ PHARMACEUTICALS

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 Answer
answered on Apr 22, 2024 at 12:51pm  

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()
}



 0



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