PHP Utility to make it easier to submit GET/POST requests to FusionPBX

Status
Not open for further replies.

xisonc

New Member
May 22, 2017
4
2
3
33
I built a very simple PHP class that handles cookies and CSRF tokens automatically to make it easier to create GET and POST requests for FusionPBX.

This is NOT a REST API replacement, but it can be used to build your own tools to interact with FusionPBX in PHP.

Check it out on Github: https://github.com/xisonc/fusionpbx-util/

Here's an example of creating a new destination:

PHP:
<?php

// include the class file
include('fusionpbx_util.php');

// set up connection to server
$pbx = new FusionPBX_Util('https://sip.example.com', 'admin_username', 'admin_password');

// first we must perform a GET request to retreive the CSRF token:
$pbx->get('/app/destinations/destination_edit.php');

// then we can create a POST request to create a new destination
$vars =    [
  'destination_type'            => 'inbound',
  'destination_prefix'            => '1',
  'destination_number'            => '5550001111',
  'destination_caller_id_name'      => '',
  'destination_caller_id_number'    => '',
  'destination_context'            => 'public',
  'destination_action'            => 'transfer:1000 XML sip.example.com',
  'destination_alternate_action'    => ':',
  'user_uuid'                => '',
  'group_uuid'                => '',
  'destination_cid_name_prefix'            => '',
  'destination_record'            => '',
  'destination_hold_music'        => '',
  'destination_accountcode'        => '',
  'domain_uuid'                => 'long-domain-uuid-string-goes-here',
  'destination_order'            => '100',
  'destination_enabled'            => 'true',
  'destination_description'        => ''
];
$create = $pbx->post('/app/destinations/destination_edit.php', $vars);

// dump the output returned from Fusion:
var_dump($create);
 
  • Like
Reactions: babak and gflow
Status
Not open for further replies.