Control Incoming Routes through API


I’ve searched the Wiki but didn’t find answer to my question.

I need to control DID (Direct Inward Dialing) through API (add/edit/delete Incoming Routes) to integrate with our customer relation application.


Asterisk doesn’t have anything called “incoming routes”. The nearest thing it has is extensions, which is how FreePBX implements incoming routes. If you are using FreePBX, the equivalent of this forum is

If you are not, firstly DID is, in my view, misused in the VoIP world to simply mean a PSTN number allocated to you. Also providers have different ways of signalling this information. The request URI user part is the cleanest, and the user part of the To header is is quite common. The first directly maps to an extension in Asterisk. The latter requires code to extract and parse the To header.

The Asterisk API for run time changes to extension is in the CLI interface. However, what FreePBX actually does is to write out an updated extensions*.conf file (where its extensions.conf includes several such files) and then make Asterisk re-read the configuration. The FreePBX GUI maintains the route information in a database, and generates the .conf file from that. You need the FreePBX forum for details on whether there is an API to manipulate that database, and how to invoke it.

I see it in this way
Most modern custom applications (via browser or else) work via ARI (Asterisk REST Interface). In order to control DID you can develop a module in customer relation application.

  1. add endpoint in pjsip.conf to connect your SIP line from provider
  2. add Stasis App in extensions.conf to throw incoming calls to Stasis App
  3. custom module at the side of customer relation application should connect via websocket to asterisk to accept events on channel in JSON format with according name of Stasis App and via POST/GET/DELETE requests control call flow

I think a lot of the use of ARI is a fashion thing. Asterisk dialplan has features that make common operations, like simple IVRs simple to implement, and easy to understand, and there is also a lot of expertise available, if they go wrong.

The OP is also using FreePBX, and if he starts handling calls in ARI, he is basically throwing away everything that FreePBX provides (including the abstraction of incoming routes).

I don’t really understand why a CRM should be modifying FreePBX incoming routes. They are related to internal business structures, and telecoms infrastructure, not to customers.


Never see author of the topic mension FreePBX

Some business cases uses asterisk only as a ‘transport’ from CRM in modern way giving external app needed telephony functionality. But should agree, most corporate VoIP is good to maintain using FreePBX

Guess we all need more details about the problem in order to help author of the topic.

He used the term “incoming routes” which is one of the modules in FreePBX, the one that takes the “DID” and caller ID and decides what to do with the call.

There is a high degree of overlap between AMI and ARI, but there are still crucial differences between them. For example, ARI lets you create channels out of thin air without reference to the dialplan.

So does AMI, if you use the application and data mode. However AMI and ARI are intended for rather different use case. AMI is for general third party control. ARI is an alternative to writing custom applications in C.

Can you give an example of how to create a channel without reference to the dialplan in AMI?

Action: Originate
Channel: pjsip/fred
Application: Playback
Data: tt_monkeys
Action: Originate
Channel: pjsip/fred
Application: Stasis
Data: MyStasisApp

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.