"Fields are empty" adding extension

I’m on FreePBX 13.0.62 and I’m writing an API that I can hit remotely. From my API, I’m hitting core_devices_add with the following:

return core_devices_add(300,'sip','SIP/300','fixed',300,'Bob');
<h1>FATAL ERROR</h1>
<h3>Fields are empty</h3>
<h4>Trace Back</h4>/var/www/html/admin/modules/core/Core.class.php:1389 die_freepbx()<br />
&nbsp;&nbsp;[0]: Fields are empty<br />
<br />
/var/www/html/admin/modules/core/functions.inc.php:4228 FreePBX\modules\Core-&amp;gt;convertRequest2Array()<br />
&nbsp;&nbsp;[0]: 300<br />
&nbsp;&nbsp;[1]: sip<br />
&nbsp;&nbsp;[2]: 2<br />
<br />
/var/www/html/api/v1/ViAPI.php:62 core_devices_add()<br />
&nbsp;&nbsp;[0]: 300<br />
&nbsp;&nbsp;[1]: sip<br />
&nbsp;&nbsp;[2]: sip/300<br />
&nbsp;&nbsp;[3]: fixed<br />
&nbsp;&nbsp;[4]: 300<br />
&nbsp;&nbsp;[5]: Bob<br />
<br />
/var/www/html/api/v1/API.class.php:80 ViAPI-&amp;gt;ext()<br />
<br />
/var/www/html/api/v1/api.php:10 API-&amp;gt;processAPI()<br />
<br />
<br />

I looked at the Bulk Extensions module to see how they do it, and it looks like they make each $var array value an array also: “extension” => array(false, -1)

I tried to format my $vars in a similar way and convertRequest2Array didn’t like it. It returned an error saying that strtoupper expects a string, not an array.

This seems like a simple formatting issue. Can you please tell me how core_devices_add expects the data to be formatted? Thanks.

Do not use core_devices_add in freepbx 13. It’s a gui work around. Look in Core.class.php for the function you should use and reference BMO. Any procedural way will be broken.

Ah, I see what you’re referencing. Thanks for that. Do you have a list of the values expected by $settings?

Look in the folder functions.inc. Then the folder drivers. Chose your poison from there and then look for the word default (Im on my phone but the function name has the word default in it). Pjsip extends sip so make sure to follow the path if you are using pjsip (eg reference both pjsip and sip)

I’m leaning towards manipulating the database directly. As long as I’m careful about doing it exactly as FreePBX does it, is there any reason I shouldn’t?

If you add it through the database then you will miss out on all the hooks and asterisk database (different than the mysql db). Eg your phone won’t work if you are doing mysql only.

I’ve been trying to use core_devices_add as well until I found this post. I took a look in Core.class.php and I found a function called addDevice. Is that what I’m looking for? How can I make the php script I’m running recognize it?

I just updated FreePBX yesterday so it’s the latest version. I just need to be able to add devices and users, and tie those devices to those users from the back end. core_users_add still works (somewhat. I haven’t been able to get the password to pass correctly), but core_devices_add throws the error described by OP. Any help is appreciated.