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
get account details using access token uing javascript sdk
Tags: sdk
Dec 11, 2017 at 3:17am   •   1 replies  •  0 likes
robert-raj

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

1 Answer
answered on Dec 11, 2017 at 7:37am  
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

 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