Skip to main content

How to get account details using access token By using Javascript SDk


After login will get access token and refresh token by using this token get account detials and create subscription for this account


Thanks in advance

Hi Robert,

Here is the code to read a user extension info and phone number given an access token.

var rcsdk = new RC({
    server: process.env.RC_SERVER,
    appKey: process.env.RC_APP_KEY,
    appSecret: process.env.RC_APP_SECRET
});

var platform = rcsdk.platform();

var data = platform.auth().data();
data.token_type = "bearer"
data.expires_in = your_AccessToken_Expiration
data.access_token = your_AccessToken
data.refresh_token = your_RefreshToken
data.refresh_token_expires_in = your_RefreshToken_Expiraion
platform.auth().setData(data)

platform.get('/account/~/extension/~/')
.then(function(response) {
  var jsonObj =response.json();
  console.log(jsonObj.extensionNumber)
  console.log(jsonObj.name)
  // check API reference for more details
  // And if you want to get the phone number
  platform.get('/account/~/extension/' + jsonObj.id + '/phone-number')
  .then(function(response) {
    console.log(response)
  }).catch(function(e) {
    throw e;
  });
}).catch(function(e) {
  throw e;
});

// And subscribe for notification using pubnub
var subscription = rcsdk.createSubscription()
function subcribeForNotification(){
  var eventFilters = []
  // specify event types you want to get notification
  eventFilters.push('/restapi/v1.0/account/~/extension/~/event_type here')
  subscription.setEventFilters(eventFilters)
  .register()
  .then(function(resp){
    console.log("READY FOR RECEIVING NOTIFICATION")
  })
}
// incoming notification
subscription.on(subscription.events.notification, function(notification){
  ...
})

Hope this helps.
+ Phong

Reply