question

robert-raj8062 avatar image
robert-raj8062 asked ·

get account details using access token uing javascript sdk

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
aaa
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

· Write an Answer
Phong Vu avatar image
Phong Vu answered ·
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
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.