Automate AudioCodes SBC Management Using REST API
- damiankozlowski
- Nov 11, 2021
- 3 min read
Updated: Nov 16, 2021
AudioCodes SBCs provide UI and CLI management interfaces that allow administrators to modify any aspect of the appliance’s configuration. Administrative activities typically require users to physically connect to the SBC by using web browser or a SSH client. This approach will be suitable in most scenarios but what if your business processes require such configuration changes to be made automatically? This is a very common scenario for service providers and highly regulated enterprises. For example, you may be required to take offline backups to a third-party storage or add a new client to your shared CE Stack.
In this blog post I will create a simple API endpoint that will add a new tenant to a shared SBC, based on data supplied in the request body.
Before you start, you will need:
AudioCodes SBC.
Nodejs with Express - visit Node Base Project for deployment instructions.
Port TCP 80 opened from Node application to SBC.
Port TCP 3000 opened from a PC running Postman to Node application.
Postman application.
Out of Scope
SBC deployment.
Encryption of HTTP traffic.
Password-less authentication (stay tuned, coming soon…)
This application will leverage AudioCodes incremental CLI upload API: “/files/cliScript/incremental” to upload the new config to the SBC. You can learn more about available API endpoints here.
The overall concept is simple:
Create a cli script template for adding a new IP Group.
Supply tenant specific data to the API in the body as a JSON object.
Replace placeholder values in the cli template with data supplied in the request body.
Upload cli script to the SBC.

Implementation
Prepare CLI Template
The CLI script my be different for you depending on your SBC configuration. The easiest way to build a configuration script template is by connecting to the CLI console and executing each line one at a time and taking note of each successful command.
name [TENANT_NAME]_CAC
activate
cac-rule 0
request-type invite
limit [CAC_LIMIT]
activate
exit
exit
ip-group new
srd-name Shared_SRD
name Teams_[TENANT_NAME]
media-realm Teams
sbc-operation-mode 0
cac-profile [TENANT_NAME]_CAC
proxy-set-name Teams
ip-profile-name MSTeams
inbound-mesg-manipulation-set 2
outbound-mesg-manipulation-set 3
sip-group-name [TRUNK_FQDN]
local-host-name [TRUNK_FQDN]
always-use-source-addr enable
tags Trunk=[TENANT_NAME]
classify-by-proxy-set disable
call-setup-rules-set-id 0
proxy-keepalive-use-ipg disable
activate
exitValues in square brackets will be replaced by data from the request body (see below)
{
"tenantName": "Contoso",
"cacLimit": "20",
"trunkFqdn": "contososbc01.super-sp.com",
"sbcIp": "99.81.44.38"
}Create SBC User for API Authentication
Connect to the SBC using the graphical web interface and navigate to Administration -> Local Users menu and create a new user called api_user with Security Administrator privileges and status set to valid. Adjust security settings to meet your requirements.

Because we are using HTTP for communication between Node Server and SBC, make sure that HTTP is allowed.

Create CLI Template File
Create cli template text file inside the resources folder at the root of the Node project.

Create the API Endpoint
We need to setup a new route for the API. In the blogRoutes.js file add the path for your new API e.g. router.route('/newTenant').put(sbcActionsController.newTenant);

In the sbcActionsController.js add the newTenant function and import required modules. The Node base project should have all the necessary modules already installed.

fs module - required to read the cli template file from the local disk.
fetch and FormData modules - used for the API requests to the SBC (cli upload).
Writing API Logic
First, we make sure that the API request to the Node application contains all the mandatory data in the body and the authorisation header is present. If not, we will respond with 400 Bad Request.

Next, we read the cli template file from the local folder. Note: For production deployments it’s better to keep templates in a central location such as database or a s3/blob storage.

The content of the fill is stored in the cliTemplate variable in the text format (utf8). We can now replace all the placeholders with the actual data.

Once we have the cli script ready for upload, we need to prepare headers and request options for the fetch request.
First, we set the body as “Content-Disposition: form-data”.

Next, we set the headers and request options: Note: For the purpose of this blog, the authorization header from Postman is pass across to the AudioCodes SBC. This approach is not recommended for production deployments.

And finally, we make the request.

In the try block we make the actual fetch request to the SBC, handle errors from the SBC and respond to the client. The catch block handles network errors and all other exceptions.
Testing the API
Make sure the Node application is running and listening on port 3000. To start the application run:
npm run devPrepare Postman request
Method: PUT
Authorization: basic
Username: api_user
Password: <your password>
Body: Raw / JSON

Response should look like this:

Voila!! The IP Group for Contoso tenant was successfully created with the corresponding CAC profile.

You can clone the final project from my GitHub repository.




Great post Damian, this is a really useful feature and a nice implementation using node.js, fine stuff :+