Get Started with Call Routing

Last updated: 2021-12-03 Contributors Byrne ReesePaco VuNone
Edit this page

To help you get started using the Call Routing API, the following code samples have been provided. These code samples perform the simple function of listing the call answering rules associated with the current user. This code sample is based on our Voice quick start guides. If you have not completed that guide, we recommend you do so first, as this is an abbreviated version of that guide.

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 Routing 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 Routing 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. Select "REST API App" under "What type of app are you creating?" Click "Next."
  4. Under "Authentication" select "Password-based auth flow."
  5. Under "Security" add the following permissions:
    • ReadAccounts
  6. Under "Security" select "This app is private and will only be callable using credentials from the same RingCentral account."

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

const RC = require('@ringcentral/sdk').SDK
require('dotenv').config();

CLIENTID     = process.env.RC_CLIENT_ID
CLIENTSECRET = process.env.RC_CLIENT_SECRET
SERVER       = process.env.RC_SERVER_URL
USERNAME     = process.env.RC_USERNAME
PASSWORD     = process.env.RC_PASSWORD
EXTENSION    = process.env.RC_EXTENSION

var rcsdk = new RC({
    server:       SERVER,
    clientId:     CLIENTID,
    clientSecret: CLIENTSECRET
});
var platform = rcsdk.platform();
platform.login({
    username:  USERNAME,
    password:  PASSWORD,
    extension: EXTENSION
})

platform.on(platform.events.loginSuccess, function(response) {
  get_user_call_answering_rules()
})

async function get_user_call_answering_rules() {
  try {
    var resp = await platform.get('/restapi/v1.0/account/~/extension/~/answering-rule', {
      'view': "Detailed",
      'enabledOnly': false
    })
    var jsonObj = await resp.json()
    for (var record of jsonObj.records) {
      get_user_call_answering_rule(record.id)
    }
  } catch (e) {
    console.log(e.message)
  }
}

async function get_user_call_answering_rule(id) {
  try {
    var resp = await platform.get('/restapi/v1.0/account/~/extension/~/answering-rule/' + id)
    var jsonObj = await resp.json()
    console.log(jsonObj)
  } catch (e) {
    console.log(e.message)
  }
}
#!/usr/bin/env python
from ringcentral import SDK
import os,sys

CLIENTID     = os.environ.get('RC_CLIENT_ID')
CLIENTSECRET = os.environ.get('RC_CLIENT_SECRET')
SERVER       = os.environ.get('RC_SERVER_URL')
USERNAME     = os.environ.get('RC_USERNAME')
PASSWORD     = os.environ.get('RC_PASSWORD')
EXTENSION    = os.environ.get('RC_EXTENSION')

rcsdk = SDK( CLIENTID, CLIENTSECRET, SERVER )
platform = rcsdk.platform()
try:
  platform.login(USERNAME, EXTENSION, PASSWORD)
except:
  sys.exit("Unable to authenticate to platform. Check credentials.")

params = {
    'view': "Detailed",
    'enabledOnly': False
}
try:
    resp = platform.get('/account/~/extension/~/answering-rule', params)
    for record in resp.json().records:
        rule = platform.get('/account/~/extension/~/answering-rule/' + record.id)
        print( f'Answering rule: {rule["name"]} is of type {rule.type}' )
except Exception as e:
    sys.exit( e )
else:
    sys.exit( 0 )
<?php
require('vendor/autoload.php');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->load();

$CLIENTID     = $_ENV['RC_CLIENT_ID'];
$CLIENTSECRET = $_ENV['RC_CLIENT_SECRET'];
$SERVER       = $_ENV['RC_SERVER_URL'];
$USERNAME     = $_ENV['RC_USERNAME'];
$PASSWORD     = $_ENV['RC_PASSWORD'];
$EXTENSION    = $_ENV['RC_EXTENSION'];

$rcsdk = new RingCentral\SDK\SDK($CLIENTID, $CLIENTSECRET, $SERVER);
$platform = $rcsdk->platform();
$platform->login($USERNAME, $EXTENSION, $PASSWORD);

try {
    $resp = $platform->get('/account/~/extension/~/answering-rule',
    array(
        'view' => "Detailed",
        'enabledOnly' => False
    ));
    $jsonObj = $resp->json();
    foreach ($jsonObj->records as $record){
    // use the $record->id to read rule details
    $resp = $platform->get('/account/~/extension/~/answering-rule/' . $record->id );
    print_r($resp->text()."\n");
    }
} catch (Exception $e) {
    echo $e->getMessage()."\n";
}
?>
using System;
using System.Threading.Tasks;
using RingCentral;
using Newtonsoft.Json;

namespace Get_User_Call_Answering_Rules
{
class Program
{
    static RestClient restClient;
    static void Main(string[] args)
    {
    restClient = new RestClient(
        Environment.GetEnvironmentVariable("RC_CLIENT_ID"),
        Environment.GetEnvironmentVariable("RC_CLIENT_SECRET"),
        Environment.GetEnvironmentVariable("RC_SERVER_URL"));
    restClient.Authorize(
        Environment.GetEnvironmentVariable("RC_USERNAME"),
        Environment.GetEnvironmentVariable("RC_EXTENSION"),
        Environment.GetEnvironmentVariable("RC_PASSWORD")).Wait();
    get_user_call_answering_rules().Wait();
    }

    static private async Task get_user_call_answering_rules()
    {
    var parameters = new ListAnsweringRulesParameters();
    parameters.view = "Detailed";
    parameters.enabledOnly = "false";

    var resp = await restClient.Restapi().Account().Extension().AnsweringRule().List(parameters);
    foreach (var record in resp.records)
    {
        var rule = await restClient.Restapi().Account().Extension().AnsweringRule(record.id).Get();
        Console.WriteLine(JsonConvert.SerializeObject(rule));
    }
    }
}
}
package com.ringcentral;

import com.ringcentral.*;
import com.ringcentral.definitions.*;
import java.io.IOException;

public class ReadUserAnsweringRules {
    static RestClient rc;

    public static void main(String[] args) {
        var obj = new ReadUserAnsweringRules();
    rc = new RestClient( System.getenv("RC_CLIENT_ID"),
                 System.getenv("RC_CLIENT_SECRET"),
                 System.getenv("RC_SERVER_URL") );
    try {
        rc.authorize( System.getenv("RC_USERNAME"),
              System.getenv("RC_EXTENSION"),
              System.getenv("RC_PASSWORD") );
        obj.get_user_call_answering_rules();
    } catch (RestException | IOException e) {
        e.printStackTrace();
    }
    }

    public void get_user_call_answering_rules() throws RestException, IOException {
    var parameters         = new ListAnsweringRulesParameters();
    parameters.view        = "Detailed";
    parameters.enabledOnly = false;

    UserAnsweringRuleList response = rc.restapi().account().extension().answeringRule().list(parameters);
    for (var record : response.records) {
        var rule = rc.restapi().account().extension().answeringRule(record.id).get();
        System.out.println("Name: " + rule.name);
        System.out.println("Type: " + rule.type);
        System.out.println("---");
    }
    }
}
require 'ringcentral'
require 'dotenv/load'

CLIENTID     = ENV['RC_CLIENT_ID']
CLIENTSECRET = ENV['RC_CLIENRT_SECRET']
SERVER       = ENV['RC_SERVER_URL']
USERNAME     = ENV['RC_USERNAME']
PASSWORD     = ENV['RC_PASSWORD']
EXTENSION    = ENV['RC_EXTENSION']

$rc = RingCentral.new(CLIENTID, CLIENTSECRET, SERVER)
$rc.authorize(username: USERNAME, extension: EXTENSION, password: PASSWORD)

resp = $rc.get('/restapi/v1.0/account/~/extension/~/answering-rule', {
    view: "Detailed",
    enabledOnly: false
})
for record in resp.body['records'] do
    rule = $rc.get('/restapi/v1.0/account/~/extension/~/answering-rule/' + record['id'])
    puts rule.body
end