githubEdit

ARI Access

Short description of ARI (Asterisk REST Interface)

ARI is a RESTful API with WebSocket support that gives full control over Asterisk channels, bridges, and media streams in real time. Unlike the MikoPBX REST API, ARI works directly with the Asterisk core and is designed for building custom telephony applications.

circle-info

Detailed ARI documentation is available on the official Asterisk website: Asterisk REST Interfacearrow-up-right

What is it used for?

ARI is used when the standard PBX features are not enough and custom call handling logic is required:

  • WebRTC applications and softphones β€” web phones and mobile clients with direct media stream control

  • Interactive voice response (IVR) β€” custom menu logic unavailable through the standard dialplan

  • Conference calls β€” programmatic control of bridges and participants

  • Call recording and processing β€” real-time audio interception for analytics or transcription

  • Voice bots and assistants β€” integration with external AI services

  • Advanced queues β€” custom call distribution logic

How does it work?

ARI consists of three components:

  1. REST API β€” management of Asterisk objects: channels, bridges, recordings

  2. WebSocket (/asterisk/ari/events) β€” receiving asynchronous real-time events: incoming call, call end, DTMF keypress, etc.

  3. Stasis β€” a dialplan application that passes a channel to your ARI application for control

Typical scenario: a call enters the dialplan β†’ Stasis() passes the channel to your application β†’ the application controls the call via REST API and receives events via WebSocket.

Configuring an ARI User

  1. Before starting, you need to enable the ARI interface (it is disabled by default). Go to "System" β†’ "General Settings".

"General settings" section in MikoPBX
  1. Go to the "AMI & ARI" tab and toggle the "Use ARI Interface" switch. In the "CORS allowed origins" field, specify the domains from which requests to ARI will be made. CORS is a browser security mechanism that restricts cross-domain API requests.

Value
When to use

(empty)

Access from the same domain only

http://localhost:3000

Local development

https://app.mycompany.com

Production application

*

All origins β€” for testing purposes only

circle-exclamation
Enabling ARI
  1. Go to "System" β†’ "ARI Access".

"ARI Access" section in MikoPBX
  1. Click "Add User".

"Add User" button
  1. Fill in the following parameters:

  • Username β€” login for connection, e.g. ari_user.

  • Password β€” password for connection.

  • Description β€” description for the current user, e.g. "WebRTC Demo".

  • Applications β€” specify the names of Stasis applications the user has access to. Leave the field empty for access to all applications.

circle-info

Common applications

  • ari-app: Main ARI application

  • stasis: Base Stasis application

  • external-media: Working with external media streams

  • bridge-app: Call bridge management

  • channel-spy: Channel monitoring

Save the settings.

Configuring user access to the ARI

Connection Parameters

WebSocket

Type
URL

Regular

ws://your-mikopbx.com:8088/asterisk/ari/events

Secure (TLS)

wss://your-mikopbx.com:8089/asterisk/ari/events

Replace [application] with the name of your Stasis application.

REST API

Type
URL

HTTP

http://your-mikopbx.com:8088/asterisk/ari

HTTPS

https://your-mikopbx.com:8089/asterisk/ari/

Authentication: HTTP Basic Auth β€” ARI user login and password.

circle-info

It is recommended to use secure connections (wss:// and https://) with a valid SSL certificate. Regular ws:// and http:// are acceptable only in an isolated test environment.

Example: Hello World

This is a minimal ARI example β€” a channel enters a Stasis application, the application plays a sound file and ends the call.

The example is taken from the official Asterisk documentation: Getting Started with ARIarrow-up-right

Step 1 β€” Connect to WebSocket

Step 2 β€” Configure the Incoming Route

In MikoPBX, go to "Routing" β†’ "Dialplan Applications", create an application with the type "Asterisk Dialplan" and the following code:

Assign the application to the required incoming route.

Step 3 β€” Make a Call

When an incoming call arrives, the WebSocket will receive a StasisStart event:

Step 4 β€” Play Sound via REST API

Open a new terminal window and run the following command:

circle-info

Use the channel id from the StasisStart event!

On successful playback, you will see the following output in the terminal:

Step 5 β€” End the Call

After the call ends, the WebSocket will send a StasisEnd event:

Example: Presence Monitor

A live employee status table in the terminal β€” no incoming route or Stasis application configuration required. Works by subscribing to all station events.

Install dependencies:

As calls are made, the table will update in real time:


Full ARI documentation is available on the Asterisk website: docs.asterisk.orgarrow-up-right

Last updated

Was this helpful?