Create user and extension from PHP


I’m trying to write my own little API so that I can create extensions and users from my external web application.

I have tried this

$settings = [
	'extension' => $extension,
	'devinfo_secret' => $password,
	'name' => $name,
	'tech' => 'pjsip',
	'devinfo_sipdriver' => 'chan_pjsip',
	'userman_directory' => 1,
	'userman_assign' => 'add',
	'userman_password' => $password,
	'userman_group' => [1]
$FreePBX = FreePBX::Create();
$Userman = FreePBX::Userman();
$FreePBX->Core->addUser($settings['extension'], $settings);
$FreePBX->Core->addDevice($settings['extension'], $settings['tech'], $sip);
$Userman->addUserByDirectory(1, $extension, $password, $extension, 'Description', array("displayname"=>$name), true);
$FreePBX->Core->addDevice('99' . $settings['extension'], $settings['tech'], $webrtc);

The variables $sip and $webrtc are arrays filled with keys/values, that looks just like those FreePBX uses when creating through the webgui.

But it’s only the “webrtc” extension that can register and make calls.
When I try to register the non-webrtc extension, I see this on Asterisk:
res_pjsip_registrar.c:1082 registrar_on_rx_request: Endpoint 'anonymous' has no configured AORs
which somewhat makes sense, as there’s no entry regarding this extension in etc/asterisk/pjsip.aor.conf - only the webrtc extension.

I have looked deep in the FreePBX code, but I think it’s pretty messy with both procedural and OO mixed together and some functions returns/echos

I really hope that someone can give some input here.


I’m not sure I’m right, but could it be due to not reloading after creating the extension?

You may want to browser the gist from @lgaetz for ideas for things.

If you don’t reload, there is no valid extension in asterisk.

I do reload.
I found an error in the $sip array - it works now.

Thanks for your suggestions :slight_smile:

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