Get Started with Call Routing

Last updated: 2024-02-28Contributors
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 and obtain credentials

The first thing we need to do is create an app in the RingCentral Developer Console. 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();

var rcsdk = new RC({
    'server':       process.env.RC_SERVER_URL,
    'clientId':     process.env.RC_APP_CLIENT_ID,
    'clientSecret': process.env.RC_APP_CLIENT_SECRET
});
var platform = rcsdk.platform();
platform.login({ 'jwt':  process.env.RC_USER_JWT })

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/python

# You get the environment parameters from your
# application dashbord in your developer account
# https://developers.ringcentral.com

import os
import sys

from dotenv import load_dotenv
from ringcentral import SDK
load_dotenv()

rcsdk = SDK( os.environ.get('RC_APP_CLIENT_ID'),
             os.environ.get('RC_APP_CLIENT_SECRET'),
             os.environ.get('RC_SERVER_URL') )
platform = rcsdk.platform()
try:
  platform.login( jwt=os.environ.get('RC_USER_JWT') )
except Exception as e:
  sys.exit("Unable to authenticate to platform: " + str(e))

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
// Remember to modify the path ./../ pointing to the location where the RingCentral SDK was installed and the .env file was saved!
require('./../vendor/autoload.php');
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . './../');
$dotenv->load();

$rcsdk = new RingCentral\SDK\SDK( $_ENV['RC_APP_CLIENT_ID'],
                                  $_ENV['RC_APP_CLIENT_SECRET'],
                                  $_ENV['RC_SERVER_URL'] );
$platform = $rcsdk->platform();
$platform->login( [ "jwt" => $_ENV['RC_USER_JWT'] ] );

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 async Task Main(string[] args)
    {
      restClient = new RestClient(
      Environment.GetEnvironmentVariable("RC_APP_CLIENT_ID"),
      Environment.GetEnvironmentVariable("RC_APP_CLIENT_SECRET"),
      Environment.GetEnvironmentVariable("RC_SERVER_URL"));
      await restClient.Authorize(Environment.GetEnvironmentVariable("RC_USER_JWT"));

      await get_user_call_answering_rules();
    }

    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_APP_CLIENT_ID"),
                 System.getenv("RC_APP_CLIENT_SECRET"),
                 System.getenv("RC_SERVER_URL") );
    try {
        rc.authorize( System.getenv("RC_USER_JWT") );
        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("---");
    }
    }
}
#!usr/bin/ruby

# You get the environment parameters from your
# application dashbord in your developer account
# https://developers.ringcentral.com

require 'ringcentral'
require 'dotenv/load'

$rc = RingCentral.new(ENV['RC_APP_CLIENT_ID'],
                      ENV['RC_APP_CLIENT_SECRET'],
                      ENV['RC_SERVER_URL'])

$rc.authorize(jwt: ENV['RC_USER_JWT'])

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