Get List of Extension or Create Extension through REST API

Hi to all.
I am using FreePBX 14.0.1.1 version. I am new to this.

I need to create Extension from my application and get list of extensions also. Is FreePBX provides any REST API to do this or need to purchase any other tool.

Thanks in advance!

Freepbx has no API to do this

While there’s no direct API, you can query the online database from the Asterisk CLI (and by extension, the AMI/ARI interface) and get the known extensions through querying the /AMPUSER/ family.

cli> database show AMPUSER

It’s not as elegant and REST-API, but if what you want is the data, it’s a way.

Thanks for your reply @cynjut and @tm1000

Is it possible to create Extension using MySQL ?

Is it possible tell me how to know the MySQL DB User privileges ? I just install FreePBX through the .iso File only.I am new to Linux too :frowning:

Or is it possible to do via CRM

No. But you can use the Bulk Handler from the CLI to create an extension:
https://wiki.freepbx.org/pages/viewpage.action?pageId=37912685#fwconsolecommands(13+)-BulkImport

@lgaetz Thanks for your response.

My overall need is to create extension from the my own web application, which is run on the another one PC on the same LAN.

To achieve that, Is it possible to run the command through java application, which is run on the FREEPBX Server PC ?

Is it possible/correct way ?

Hello @karthick,

You can write a web service that will help to execute console commands on the Freepbx server.
You will send a URL with specific parameters from your application like extension number, extension name, password, outbound cli etc, and then issue the fwconsole command with the received parameters in your web service.

I suggest you to first export the configuration (bulk handler module) so you can check the csv format of an extension, and then issue the fwconsole bi command from the console to see if it is working.

fwconsole bi --type='extensions' extensions.csv

Then you need to send the fwconsole reload command to apply the settings.

If you really want to add, edit or delete extensions, you can explore the bulk handler module and use the main functions in your web service.

Thank you,

Daniel Friedman
Trixton LTD.

1 Like

Thank you so much @danielf your idea is working like charm :slight_smile::sweat_smile:.

From my java application also I can able to upload the CSV file.

For the every extension add I have to upload one CSV file. Is there any other possibility to do that.

Thank you,

Karthick Ramu

Hello @karthick,

It is good to hear that you solved your problems. As for your question regarding using a csv file for every extension, you can always do it one time if you need to configure several extensions. Just add the extensions lines to the csv file, and the fwconsole bi process will iterate through the lines in the csv file and add the extensions at once. That is why it is called the bulk handler module.

I hope that I understood you correctly. If not, please elaborate more.
Can you share your web service application with the rest of us?

Thank you,

Daniel Friedman
Trixton LTD.

Hello @danielf,

Sorry for the late response.

I have created one Java TCP application. To create contact from another application, I just get the needed information like user name, password, extension number,etc…

After receiving those information, I had created one CSV file for that extension and with the help of Process comments I had execute the command. Once the command is executed I just delete the file.

fwconsole bi --type=‘extensions’ extensions.csv

Like the way I am adding extension to FreePBX server. With the help of this command can able to only add the extension. Not able to edit the Extension.

For example, if I alter the password for the extension 105, command shows imported successfully. Its not overwrite the extension 105.

Is there any possible to overwrite the extension ?

Not from the CLI at this time

Speaking of RestAPIs. By October FreePBX 15 will be in beta with a Rest-like API.

@tm1000 Very happy to hear this message Andrew Nagy.

One more doubt for me.Maximum, how many simultaneous calls will be supported by FreePBX with Asterisk ?

Hello @karthick,

If you want to edit your existing extensions, you can delete it and add it again.
You can use this php script of @lgaetz to delete extensions (from Freepbx Ver.13):

#!/usr/bin/env php
<?php
if (!isset($argv[1])){
	echo "
 ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
 *
 * Script: extension-del.php
 *
 * Latest version: https://gist.github.com/lgaetz/f2d3d717520f8adf2018643473d1f748
 *
 * Usage: Run at bash prompt of FreePBX system running FreePBX 13+ with single argument 
 *        of extension to be deleted. Follow with fwconsole reload for changes to be applied 
 *
 *        # extension-del.php 3002
 *
 * License: GNU/GPL3+
 *
 * History:
 *         2017-09-24   First commit by lgaetz
 *         2017-09-25   Update for virtual extensions
 *         2017-09-26   General polish
 ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** *****
";
exit;
} 
 
include '/etc/freepbx.conf';
$FreePBX = FreePBX::Create();
$device=$FreePBX->Core->getDevice($argv[1]);
$user=$FreePBX->Core->getUser($argv[1]);
if($device["user"]){
	// normal extensions tested with sip, pjsip and dahdi
	echo "Found device ".$argv[1].", deleting...\n";
	echo "Found user ".$device["user"].", deleting...\n";
	$foo=$FreePBX->Core->delDevice($argv[1]);
	$foo=$FreePBX->Core->delUser($device["user"]);
} elseif ($user) {
	// for extensions with users but no device i.e. virtual
	echo "Found user ".$user['extension'].", deleting...\n";
	$foo=$FreePBX->Core->delUser($argv[1]);
} else {
	echo "Neither user nor device ".$argv[1]." exists, exiting...\n";
}

Thank you,

Daniel Friedman
Trixton LTD.

2 Likes