Difference between revisions of "Proxyapi"

From MiRTA PBX documentation
Jump to navigation Jump to search
Line 473: Line 473:
  
 
https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=user&action=get&objectid=3635
 
https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=user&action=get&objectid=3635
 +
 +
=== Creating an user ===
 +
 +
<pre>
 +
<?php
 +
$user['us_username']='Leandro71';
 +
$user['us_password']=hash('sha256','nabucco347');
 +
$user['us_up_id']=1;
 +
 +
$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=add&object=user";
 +
$resource = curl_init();
 +
curl_setopt($resource, CURLOPT_URL, $url);
 +
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
 +
curl_setopt($resource, CURLOPT_VERBOSE, true);
 +
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($user)));
 +
$data = curl_exec($resource);
 +
curl_close($resource);
 +
 +
print_r($data);
 +
?>
 +
 +
</pre>

Revision as of 16:13, 23 February 2021

Proxyapi is the way to manage your PBX from external softwares. It allows easy access to calls, phone status and more. It allows also to create, delete and edit records, even if in a limited way.

Proxyapi can be used by each tenant using an API key generated in the Configuration/Settings page. Two kinds of keys can be generated, one allowing Read/Write access and one allowing only read-only operations.

The latest syntax for the operations can be retrieved by proxyapi itself, like for example: https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=HELP

Some usage example examples (please note the URL on the demo server is slightly different than on production servers - mirtapbx/pbx):

Contents

INFO - SIMPLECDRS / Get the list of calls

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=SIMPLECDRS&tenant=DEVEL&calleridnum=103,104&start=2020-01-01&end=2020-12-31

INFO - CDRS / Get the list of calls

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=CDRS&tenant=DEVEL&phone=103,104&start=2019-12-01&end=2019-12-31

INFO - DIDS / Get the list of DIDs for one tenant

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=DIDS&tenant=DEVEL

INFO - DIDS / Get the list of DIDs for all tenants

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=DIDS

DIAL / Call an extension and then dial a number

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=DIAL&source=402&dest=9922323232&tenant=DEVEL&account=402-DEVEL

This command returns a call id like:

Success|Originate successfully queued|15a4cfe6429054|

The call id can be used to retrieve the recording with

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=recording&id=15a4cfe6429054

It will be contained in the "OriginateID" field in the cdr table

You can provide variables to the dial plan, by using the var parameter like:

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=DIAL&source=402&dest=9922323232&tenant=DEVEL&account=402-DEVEL&var=callid%3D453131

%3D is the URL encoded equivalent of =

The variable will be available in the dial plan as "TENANTCODE-variable". In this example as DEVEL-callid

HANGUP / Hangup a call by extension

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=HANGUP&extension=103-DEVEL&tenant=DEVEL

AGENT / Pause agent from queue

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=AGENT&action=PAUSE&queue=281&extension=104-DEVEL&tenant=DEVEL&pausereason=Breakfast

MEDIAFILE / Retrieve a media file by its ID

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MEDIAFILE&tenant=DEVEL&id=19&action=GETAUDIO&objectid=3619

QUEUE / Get the list of agents

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=QUEUE&tenant=DEVEL&action=list&number=9200

QUEUE / Add an agent to a queue

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=QUEUE&tenant=DEVEL&action=add&number=9200&extension=103

VOICEMAIL

Get all voicemails for a tenant

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=VOICEMAIL&tenant=DEVEL&action=list

Get info about voicemails in a mailbox

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=VOICEMAIL&tenant=DEVEL&mailbox=102&action=messages

Get the binary audio for a message

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=VOICEMAIL&tenant=DEVEL&mailbox=102&action=message&msgid=1475685709-00000004

COUNTCALLS / Count the calls on a system

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=COUNTCALLS

RECORDINGS / Get or play a recording

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=recording&id=srv02-1531779475.48&tenant=DEVEL

Based on your browser settings, you can force the browser to play the recording using the "playrecording" info parameter

PHONEBOOKS

Search for an entry

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=PHONEBOOK&subreqtype=query&tenant=DEVEL&phonebook=Default&field=name&value=Ben

Add an entry

<?php

$phonebook['NAME']="Ross";
$phonebook['PHONE1']="3564732920";

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=PHONEBOOK&subreqtype=add&phonebook=Default&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "values=".urlencode(json_encode($phonebook)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

?>

FAX

Send a fax

<?php
$postfields = array(
    'filename' => '@protected/FAXtestPage.pdf'
                    );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=FAX&action=send&number=99397654321&source_number=123412345&tenant=DEVEL");
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

if (curl_errno($ch)) {
  print curl_error($ch);
}
curl_close($ch);

INFO

Get the cdr for a tenant in CSV format

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=CDRS&format=csv&tenant=DEVEL&start=2017-01-01&end=2017-02-01

Get the cdr for all tenants in CSV format

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=CDRS&format=csv&tenant=%&start=2017-01-01&end=2017-02-01

Please note, when getting the CSV for a single tenant, the CSV format used is the tenant one, when getting the CSV for multiple tenants, the Admin format is used

Get the queue log for a tenant in CSV format

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=INFO&info=QUEUELOGS&format=csv&tenant=DEVEL&start=2017-10-01&end=2017-12-01

Getting response paths results

Getting the latest one for a given Response Path

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=RESPONSEPATH&tenant=DEVEL&id=19&action=GETLAST

It returns something like:

UniqueID|Type|Type ID|Value|Type Name|Value Name
srv02-1509806457.625|START|0|2017-11-04 15:41:01||
srv02-1509806457.625|CALLERID|0|Susan <1132555678>||
srv02-1509806457.625|VARIABLE|85|36985||
srv02-1509806457.625|VARIABLE|144|56896||
srv02-1509806457.625|QUEUE|281|||
srv02-1509806457.625|ANSWER|0|105-DEVEL||
srv02-1509806457.625|HANGUP|0|||

Getting the latest one for a given Response Path for agent 104-DEVEL

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=RESPONSEPATH&tenant=DEVEL&id=19&action=GETLAST&filter=ANSWER&filterdata=104-DEVEL

Getting the latest one for a given Response Path for agent 104-DEVEL in xml format

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=RESPONSEPATH&tenant=DEVEL&id=19&action=GETLAST&filter=ANSWER&filterdata=105-DEVEL&format=xml

Based on the xml format shown in the manual, it returns something like:

<?xml version="1.0">
<Result>
<Agent>105-DEVEL</Agent>
<Status>NOT ACTIVE</Status>
<Queue>supportQ</Queue>
<ClientID>1234</MemberNumber>
<OrderNumber>11223344</MemberNumber>
<Caller>Manuel <7171345678></Caller>
<VoiceFile>3619</VoiceFile>
</Result>

ManageDB

Any ManageDB action requires an admin key

ManageDB / Custom Destination Types

Getting the custom destination type list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=CUSTOMTYPES&tenant=DEVEL&action=list

ManageDB / Custom Destinations

Getting the custom destination list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=CUSTOM&tenant=DEVEL&action=list

Getting info for a custom destination

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=CUSTOM&tenant=DEVEL&action=get&objectid=67

Creating a custom destination

$config['cu_name']="Boss phone";
$config['cu_ct_id']=1;
$config['cu_param1']="3564732920";
$config['cu_param2']="INCOMINGDID";
$config['cu_param3']="30";

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=add&object=custom&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

Updating a custom destination

$config['cu_name']="Boss private phone";
$config['cu_id']=286;
$config['cu_param1']="0636287454";

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=update&object=custom&tenant=DEVEL&objectid=286";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

ManageDB / Tenants

Getting the tenant list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=TENANT&action=list

Getting info for a tenant

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=TENANT&action=get&objectid=1

Creating a tenant

$config['te_code']="RELAX";
$config['te_name']="Relax & entertainment";
$config['pk_start']=800;
$config['pk_end']=810;

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=add&object=tenant";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

Updating a tenant

$config['te_name']="Relax and entertainment";
$config['pk_end']=820;

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=update&object=tenant&objectid=460";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

ManageDB / Phones

Getting the phones list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=PHONE&action=list&tenant=DEVEL

Getting info for a phone

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=PHONE&action=get&objectid=182&tenant=DEVEL

Creating a phone

$config['ph_name']="George Basement";
$config['ph_mac']='AA:BB:CC:DD:EE:FF:00:11';
$config['ph_pm_id']=5;

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=add&object=phones&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

Updating a phone


$config['ph_name']="George Lower Basement";

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=update&object=phone&objectid=207&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

Manage DB / media files

Getting the media file list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=MEDIAFILE&action=list&tenant=DEVEL

Getting info for a media file

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=MEDIAFILE&action=get&objectid=1063&tenant=DEVEL

Getting the binary part of a media file

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=MEDIAFILE&action=getbinary&objectid=1063&tenant=DEVEL

Updating a media file


$config['me_name']="Beep";

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=update&object=mediafile&objectid=10&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($config)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);

Updating the binary part of a media file


<?php
$postfields = array(
    'filename' => '@audio.wav'
                    );

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=MEDIAFILE&action=updatebinary&objectid=247&tenant=DEVEL");
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);

if (curl_errno($ch)) {
  print curl_error($ch);
}
curl_close($ch); 

ManageDB / Hunt Lists

Getting the hunt lists list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=HUNTLIST&action=get&objectid=323&tenant=DEVEL

Getting the hunt lists extension list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=HUNTLIST&action=getextensions&objectid=323&tenant=DEVEL

Setting the hunt lists extension list

<?php
$destinations=array('EXT-1701','EXT-1703','EXT-1705','CUSTOM-67');

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=setextensions&object=huntlist&objectid=26&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($destinations)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);
?>

ManageDB / Extensions

Getting the extension list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=list&object=extension&tenant=DEVEL

Updating the security for an extension

<?php

$value['ex_callallowed']='none'; 
//$value['ex_callallowed']='all'; 

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=update&object=extension&objectid=1695&tenant=DEVEL";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($value)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);
?>

ManageDB / Users

Getting the user list

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=user&action=list

Getting the details for an user

https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&object=user&action=get&objectid=3635

Creating an user

<?php
$user['us_username']='Leandro71';
$user['us_password']=hash('sha256','nabucco347');
$user['us_up_id']=1;

$url = "https://demo.mirtapbx.com/mirtapbx/proxyapi.php?key=NLbP7GFNVRqu9SDm&reqtype=MANAGEDB&action=add&object=user";
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($resource, CURLOPT_VERBOSE, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, "jsondata=".urlencode(json_encode($user)));
$data = curl_exec($resource);
curl_close($resource);

print_r($data);
?>