Error when trying to add device programmatically

Hi there,

I’m using the latest version of the FreePBX Distro with FreePBX 13.0 with Asterisk 13.12 on Ubuntu.
I was building a program to add devices automatically using bootstrap but when testing the core_devices_add() function with all parameters filled in I keep getting this exception :

[[email protected] ~]# php DevicesScript.php 
locale: Cannot set LC_CTYPE to default locale: No such file or directory
Exception: Account must be set! in file /var/www/html/admin/modules/core/Core.class.php on line 1315
Stack trace:
  1. Exception->() /var/www/html/admin/modules/core/Core.class.php:1315
  2. FreePBX\modules\Core->convertRequest2Array() /var/www/html/admin/modules/core/functions.inc.php:4099
  3. core_devices_add() /root/DevicesScript.php:51

EDIT :

I found this example in the freepbx documentation so I tried to use it but it still gives the same exception

<?php
$bootstrap_settings = array();
$bootstrap_settings['freepbx_auth'] = false;
if ([email protected]_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
      include_once('/etc/asterisk/freepbx.conf');
}

/*
USER VARS:
Array
(
    [extension] => 0224
    [password] =>
    [name] => Display Name
    [voicemail] => default
    [ringtimer] => 0
    [noanswer] =>
    [recording] =>
    [outboundcid] =>
    [sipname] =>
    [noanswer_cid] =>
    [busy_cid] =>
    [chanunavail_cid] =>
    [noanswer_dest] =>
    [busy_dest] =>
    [chanunavail_dest] =>
    [mohclass] => default
    [callwaiting] => enabled
    [cid_masquerade] => 0224
    [call_screen] => 0
    [pinless] => disabled
    [cfringtimer] => 0
    [concurrency_limit] => 0
    [dialopts] =>
    [recording_in_external] => dontcare
    [recording_out_external] => dontcare
    [recording_in_internal] => dontcare
    [recording_out_internal] => dontcare
    [recording_ondemand] => disabled
    [recording_priority] => 10
)
*/
$vars = array(
"extension" => 255,
"name" => "Bobby",
"password" => base64_encode(openssl_random_pseudo_bytes(30))
);
core_users_add($vars);
//core_devices_add($id,$tech,$dial,$devicetype,$user,$description,$emergency_cid=null,$editmode=false)

core_devices_add(255,'sip','','fixed',255,'Bobby'); 
?>

Even though I didn’t code the file where the exception is thrown. I was hoping some of you might know how to solve this exception.

Kind regards,
Lowie Daniels

Are you familiar with the Bulk Import support in fwconsole:
http://wiki.freepbx.org/pages/viewpage.action?pageId=37912685#fwconsolecommands(13+)-BulkImport

fwconsole  bulkimport --help

No I wasn’t so I can just write a bashscript using these commands ?

THis also doesn’t look like a solution for my problem.

From your original stated problem, it’s not clear to me how a bulk import cannot be a reasonable solution for you?

Please explain what you are trying to do that a Bulk Import tails to do for you and we will endeavor to help you.

Well I’m looking to bulkimport devices only but the function bulkimport only imports complete extensions (which is useless since I add users seperately as well) , DID’s, blacklist and contacts, not individual devices I think ? Please correct me if I’m wrong

The Function to add devices…

1 Like

I have been trying to use this error but keep getting the same error :

PHP Fatal error: Class ‘FreePBX_Helpers’ not found in /var/www/html/admin/modules/core/Core.class.php on line 4

Do you know where this comes from ? It shows this error when I try to include the core.class.php file

You need to read the wiki and not double post.

Hi everybody,

I’m using the latest distro of FreePBX.
I tried to simply add a device programmatically but keep getting the same error :

PHP Fatal error: Class ‘FreePBX_Helpers’ not found in /var/www/html/admin/modules/core/Core.class.php on line 4

This is the small test-program I use :

<?php
namespace FreePBX\modules;

include("/var/www/html/admin/modules/core/Core.class.php");

    class Automation extends \FreePBX_Helpers
    {
        function __construct()
        {
            $this->pushDevToDB();
        }

        function pushDevToDB() {
            $core = new Core();
            $core->addDevice(100, 'sip');
        }

    }

Can anyone help me on how to get started by solving this issue ? Or maybe helping me with an example of code that works to add a device ?

Yours sincerely,
Lowie

You can’t do this. Please read the wiki.