This is a library implemented in typescript which provides convenient APIs for typescript/javascript developers to access RingCentral REST API. It can be used in both node.js and browser. Full API Reference.
To perform subsequent operations, you need a ringcentral appKey (apply at https://developer.ringcentral.com/) and a ringcentral account.
Quick Start
Login, logout, get current ringcentral account info.
let rc =newRingCentral({
server:SERVER_SANDBOX,// You should use SERVER_PRODUCTION in production
appKey:'{yourAppKey}',
appSecret:'{yourAppSecret}'
});
// Log into RingCentral
rc.auth({
username:'{username}',
extension:'{extension}',
password:'{password}'
}).then(()=>{
console.log('login success');
returnrc.account().get();// Call RingCentral REST API
}).then(accountInfo=>{
console.log("Current account info", accountInfo);
returnrc.logout();// Logout
}).then(()=>{
console.log("logout success");
}).catch(e=>{
console.error('Error occured', e);
});
Rate limit handling
You can only call RingCentral API at limited rate. By default, when rate limit hit, it will wait until the service is available and resend the API request. To prevent this behavior, you can set the handleRateLimit option of the constructor:
let rc =newRingCentral({
handleRateLimit:false,
...
});
TokenStore
By default the token is stored in memory, it will be lost when the process exits in node or the web page reloads. You can specify a TokenStore to cache the token in localStorage, file, redis or other databases, etc.
Creating Token Store:
// In browser, you can cache the token in localStorage
let tokenStore =newFileTotkenStorage('{filePathToStoreTheToken}');
Check token in token store:
let rc =newRingCentral({
tokenStore
...
});
rc.getToken({// Optionally, you can specify the username and extension to check with the stored token.
username:'xxx',
extension:'xxx'
}).then((token)=>{
console.log('Token is valid in the token store', token);
},e=>{
console.log('Fail to load token from tokenStore, possible reasons: the access token and refresh token in the store both expire; no token is cached in the store; the cached token is created by a different appKey or RC account.');
returnrc.auth({// Create new token by password or oauth
...
});
});
Except for memory, localStorage and file, you can also implement your own TokenStore to cache the token in other places.
API Call Examples
Telephony Calls
Make phone calls by ringout(https://developer.ringcentral.com/api-docs/latest/index.html#!#MakeRingOut.html):
rc.account().extension().ringout().post({
from:{ phoneNumber:'xxx'},
to:{ phoneNumber:'xxx'},
callerId:{ phoneNumber:'xxx'}
}).then(ringout=>{
console.log('Ringout sucess', ringout);
// To check the call status: `rc.account().extension().ringout(ringout.id).get();`
},e=>{
console.error('Fail to ringout', e);
});
Track the telephony status
To get notications when calls come in, go out or ends, subscribe to the Presence Event: