Call Answering Rules JavaScript Quick Start

Last updated: 2019-12-12 Contributors Embbnux JiByrne ReesePaco Vu

Welcome to the RingCentral Platform. RingCentral is the leading unified communications platform. From one system developers can integrate with, or build products around all the ways people communicate today: SMS, voice, fax, chat and meetings.

In this Quick Start, we are going to read preset call answering rules of a user, so that you can see the rule's details and update the rule with new values if you want to. Let's get started.

Create an App

The first thing we need to do is create an app in the RingCentral Developer Portal. This can be done quickly by clicking the "Create Call Management App" button below. Just click the button, enter a name and description if you choose, and click the "Create" button. If you do not yet have a RingCentral account, you will be prompted to create one.

Create Call Management App

  1. Login or create an account if you have not done so already.
  2. Go to Console/Apps and click 'Create App' button.
  3. Give your app a name and description, then click Next.
  4. On the second page of the create app wizard enter the following:
    • Select 'Private' for Application Type.
    • Select 'Server-only (No UI)' for Platform Type.
  5. On the third page of the create app wizard, select the following permissions:
    • ReadAccounts
  6. We are using Password Flow authentication, so leave "OAuth Redirect URI" blank.

When you are done, you will be taken to the app's dashboard. Make note of the Client ID and Client Secret. We will be using those momentarily.

Read User Call Answering Rules

Install RingCentral Node JS SDK

$ npm install @ringcentral/sdk --save

Create and Edit get-call-answering_rules.js

Create a file called get-call-answering_rules.js. Be sure to edit the variables in ALL CAPS with your app and user credentials.

const SDK = require('@ringcentral/sdk').SDK

RINGCENTRAL_CLIENTID = '<ENTER CLIENT ID>'
RINGCENTRAL_CLIENTSECRET = '<ENTER CLIENT SECRET>'
RINGCENTRAL_SERVER = 'https://platform.devtest.ringcentral.com'

RINGCENTRAL_USERNAME = '<YOUR ACCOUNT PHONE NUMBER>'
RINGCENTRAL_PASSWORD = '<YOUR ACCOUNT PASSWORD>'
RINGCENTRAL_EXTENSION = '<YOUR EXTENSION, PROBABLY "101">'

var rcsdk = new SDK({
      server: RINGCENTRAL_SERVER,
      clientId: RINGCENTRAL_CLIENTID,
      clientSecret: RINGCENTRAL_CLIENTSECRET
  });
var platform = rcsdk.platform();
platform.login({
      username: RINGCENTRAL_USERNAME,
      password: RINGCENTRAL_PASSWORD,
      extension: RINGCENTRAL_EXTENSION
      })
      .then(function(resp) {
          get_user_call_answering_rules()
      });

function get_user_call_answering_rules() {
    platform.get('/restapi/v1.0/account/~/extension/~/answering-rule', {
        'view': "Detailed",
        'enabledOnly': false
      })
      .then(function(resp){
          return resp.json()
      }).then(function(jsonObj) {
        for (var record of jsonObj.records){
          // use the record.id to read rule details
          get_user_call_answering_rule(record.id)
        }
      })
      .catch(function(e){
          console.log(e.message)
      })
}

function get_user_call_answering_rule(id) {
    platform.get('/restapi/v1.0/account/~/extension/~/answering-rule/' + id )
        .then(function(resp){
          return resp.text()
        })
        .then(function(text) {
          console.log(text)
        })
        .catch(function(e){
            console.log(e.message)
        })
}

Run Your Code

You are almost done. Now run your script.

$ node get-call-answering_rules.js

Need Help?

Having difficulty? Feeling frustrated? Receiving an error you don't understand? Our community is here to help and may already have found an answer. Search our community forums, and if you don't find an answer please ask!

Search the forums »

What's Next?

When you have successfully made your first API call, it is time to take your next step towards building a more robust RingCentral application.

Take your next step »