Difference between revisions of "WEB API"

From VoIPmonitor.org
Jump to navigation Jump to search
Line 158: Line 158:
 
Output is JSON formated array of CDR  
 
Output is JSON formated array of CDR  
  
  curl '192.168.76.201/voipmonitor/php/model/sql.php?module=bypass_login&user=voipmonitor&pass=voipmonitor'
+
  curl '192.168.76.201/php/model/sql.php?module=bypass_login&user=voipmonitor&pass=voipmonitor'
  take the SID which you will put to PHPSESSID curl -X POST -k --cookie "PHPSESSID=28a5395da414b1a20e4723e0651c9f0b" "http://192.168.76.201/voipmonitor/php/model/sql.php?task=LISTING&module=CDR&fcaller=190"
+
  take the SID which you will put to PHPSESSID curl -X POST -k --cookie "PHPSESSID=28a5395da414b1a20e4723e0651c9f0b" "http://192.168.76.201/php/model/sql.php?task=LISTING&module=CDR&fcaller=190"
  
  
Line 206: Line 206:
 
  echo '{"task": "getVoipCalls", "user": "USER", "password": "PASSWORD", "params": [{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251414"},{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251415"}]}' | php api.php         
 
  echo '{"task": "getVoipCalls", "user": "USER", "password": "PASSWORD", "params": [{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251414"},{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251415"}]}' | php api.php         
 
==== HTTP GET Simple parameter ====
 
==== HTTP GET Simple parameter ====
  http://localhost/voipmon/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params={"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"}
+
  http://localhost/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params={"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"}
 
   
 
   
 
==== HTTP GET Array parameter ====
 
==== HTTP GET Array parameter ====
  http://localhost/voipmon/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params=[{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"},{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251415"}]
+
  http://localhost/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params=[{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"},{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251415"}]
  
 
== getVoiceRecording by Cdr ID ==
 
== getVoiceRecording by Cdr ID ==
Line 225: Line 225:
  
 
==== HTTP GET ====  
 
==== HTTP GET ====  
  http://localhost/voipmon/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"cdrId":4919}
+
  http://localhost/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"cdrId":4919}
  
 
== getVoiceRecording by Call ID ==
 
== getVoiceRecording by Call ID ==
Line 241: Line 241:
  
 
==== HTTP GET ====
 
==== HTTP GET ====
  http://localhost/voipmon/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"callId":"XXXXXXXXXXXXXXXXXXXXXX"}
+
  http://localhost/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"callId":"XXXXXXXXXXXXXXXXXXXXXX"}

Revision as of 11:46, 26 March 2014

Custom Login

Custom login allows to implement your own login mechanism. You need to create file scripts/custom_login.php and function custom_login

custom login script: /scripts/custom_login.php

<?php

function custom_login($user, $password) {
        debug_log('custom_login');
        return(array(
                'username' => $user,
                'is_admin' => false,
                'enable_sensors' => array(2,3)
        ));
}


The array can return those parameters:

  • enable_sensors - array(A,B,...) where the number is number of the sensor. If no enable_sensors provided the user will see all sensors CDR.
  • username
  • name
  • password
  • ip
  • number
  • domain
  • id_group
  • note
  • can_listen
  • no_rtp
  • can_show_fax
  • can_pcap
  • is_admin
  • simple_cdr
  • dynamic_cdr_title
  • can_tracker
  • can_activecalls
  • can_register
  • can_livesniffer
  • can_capture_rules
  • can_audit
  • can_alerts_edit
  • can_alerts_show_sent
  • can_reports_edit
  • can_reports_show_sent
  • can_cdr_share
  • can_cdr_share_voipmonitor_org
  • hide_license_information
  • can_ipacc
  • email
  • uc_color_theme_shift_h
  • uc_color_theme_shift_s
  • uc_color_theme_shift_v
  • uc_color_theme_shift
  • uc_font_main_menu

CDR HTTP API

This method allows to get CDR rows formatted in JSON which you can see in the WEB GUI using the same filter which you can see in the WGB GUI: Call_Detail_Record_-_CDR#Filter_Form_button

You need to have valid session GUI_automate_login and you have to send those parameters via POST request

INPUT

HTTP POST address - php/model/sql.php

Mandatory parameters

task:LISTING module:CDR

Datetime range

fdatefrom:1986-01-09T00:00:00 fdateto:2013-05-28T00:00:00

Caller / called numbers

fcaller: caller num
fcalled: called num
fcallerd_type: 0 (if type is 0 searching is done for fcaller OR fcalled and value is taken from fcaller. If value is 1 searching is done for fcaller AND fcalled)


Domain

fcaller_domain: caller domain fcalled_domain: caller domain
fcallerd_domain_type:0 (if type is 0 searching is done for fcaller OR fcalled and value is taken from fcaller. If value is 1 searching is done for fcaller AND fcalled)

Caller id name

fcallername: caller name

SIP caller / called IP

fsipcallerip: caller SIP IP fsipcalledip: called SIP IP
fsipcallerdip_type:0 (if type is 0 searching is done for fcaller OR fcalled and value is taken from fcaller. If value is 1 searching is done for fcaller AND fcalled)

RTP source / destination IP

fa_saddr: 192.168.0.1
fb_saddr: 192.168.0.2
fab_saddr_type:0 (if type is 0 searching is done for fcaller OR fcalled and value is taken from fcaller. If value is 1 searching is done for fcaller AND fcalled)

Codecs

fcodec: 4, 12

list of numbers delimited by ','. Here is list of numbers and its codecs

define("PAYLOAD_PCMU", 0); define("PAYLOAD_GSM", 3); define("PAYLOAD_G723", 4); define("PAYLOAD_PCMA", 8); define("PAYLOAD_G722", 9); define("PAYLOAD_QCELP", 12); define("PAYLOAD_CN", 13); define("PAYLOAD_G729", 18); define("PAYLOAD_ILBC", 97); define("PAYLOAD_SPEEX", 98); define("PAYLOAD_SILK", 301); define("PAYLOAD_SILK8", 302); define("PAYLOAD_SILK12", 303); define("PAYLOAD_SILK16", 304); define("PAYLOAD_SILK24", 305); define("PAYLOAD_ISAC", 306); define("PAYLOAD_ISAC16", 307); define("PAYLOAD_ISAC32", 308); define("PAYLOAD_T38", 1000);

Call duration

example: less than 30 and greater than 10 seconds

fdurationgt: 30 fdurationlt: 10

PDD

example: greater than 10 and less than 30 seconds

fpddgt: 10 fpddlt: 30

Sip response code

fsipresponse: 503

Interrupted call

false or true

fbye:false

Direction (by trunk)

false or true

ftrunk:

SIP user agent

fa_ua: caller agent string fb_ua: called agent string
fab_ua_type:0 (if type is 0 searching is done for fcaller OR fcalled and value is taken from fcaller. If value is 1 searching is done for fcaller AND fcalled)

SIP Call-ID header

fcallid: string

SIP sensor ID (database ID)

fsensor_id:


Paging

page:1 start:0 limit:30

Ordering

sort:[{"property":"calldate2","direction":"DESC"}]


Special Ordering

orderByLoss: orderByDelay: orderByFixed1: orderByFixed2: orderByAdapt: orderByCallDuration_asc: orderByCallDuration_desc: orderBySrcSIP_IP_asc: orderBySrcSIP_IP_desc: orderByDstSIP_IP_asc: orderByDstSIP_IP_desc: orderBySrcNumber_asc: orderBySrcNumber_desc: orderByDstNumber_asc: orderByDstNumber_desc: orderByCallerName_asc: orderByCallerName_desc: orderByLastSIPrespNum_asc: orderByLastSIPrespNum_desc:

RTP

frtcp_maxjitter: frtcp_avgjitter: frtcp_maxfr: frtcp_avgfr: fmosf1: fmosf2: fmosadapt: f_d50: f_d70: f_d90: f_d120: f_d150: f_d200: f_d300: floss1: floss2: floss3: floss4: floss5: floss6: floss7: floss8: floss9: floss10: ffilterTemplate:

OUTPUT

Output is JSON formated array of CDR

curl '192.168.76.201/php/model/sql.php?module=bypass_login&user=voipmonitor&pass=voipmonitor'
take the SID which you will put to PHPSESSID curl -X POST -k --cookie "PHPSESSID=28a5395da414b1a20e4723e0651c9f0b" "http://192.168.76.201/php/model/sql.php?task=LISTING&module=CDR&fcaller=190"


{"total":"25","results":[{"lastSIPresponseNum":"200","lastSIPresponse_id":"3","cnt_all":"110011","duration_all":"5388692","acd_all":"49.3737","asr_all":"99.2092","mos_all":"4.36034442","packets_lost_all":"0.15386185","jitter_all":"1.03656707","delay_all":"116.5833","cnt_ok":null,"cnt_err":null,"lastSIPresponse":"200 OK","id":"200 OK"},{"lastSIPresponseNum":"487","lastSIPresponse_id":"27","cnt_all":"535","duration_all":"256","acd_all":"6.2439","asr_all":"7.6636","mos_all":"3.67647059","packets_lost_all":"0.05965854","jitter_all":"1.00000000","delay_all":"0.5042","cnt_ok":null,"cnt_err":null,"lastSIPresponse":"487 Request Terminated","id":"487 Request Terminated"}]}



Search CDR by URL

If you would like to build URL which will show CDR in web browser matching filter you can use cdr_filter parameter for admin.php

http://localhost/admin.php?cdr_filter={fcallid:"uDR8mtloKFa1F8625VL2OXSFp.RuG73v"}

cdr_filter takes the same arguments like in section WEB_API#CDR_HTTP_API

HTTP API 2

This API was created for getting audio files based on various search criteria. Requests are over HTTP POST or GET

getVoipCalls

Input data

  • startTime - all calls which started >= startTime
  • startTimeTo - all calls which started <= startTimeTo (not mandatory)
  • callEnd - all calls which ends <= callEnd (not mandatory)
  • caller - caller number
  • called - called number
task: getVoipCalls,
user: USER,
password: PASSWORD,
params: {
 startTime: YYYY-MM-DD HH:II:SS,
 startTimeTo: YYYY-MM-DD HH:II:SS,
 callEnd: YYYY-MM-DD HH:II:SS,
 caller: 9999999,
 called: 9999999
}

Examples

HTTP POST Simple parameter

echo '{"task": "getVoipCalls", "user": "USER", "password": "PASSWORD", "params": {"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251414"}}' | php api.php

HTTP POST Array parameter

echo '{"task": "getVoipCalls", "user": "USER", "password": "PASSWORD", "params": [{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251414"},{"startTime": "2013-01-01", "endTime": "2013-08-01", "caller": "910251415"}]}' | php api.php        

HTTP GET Simple parameter

http://localhost/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params={"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"}

HTTP GET Array parameter

http://localhost/php/api.php?task=getVoipCalls&user=USER&password=PASSWORD&params=[{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251414"},{"startTime":"2013-01-01","endTime":"2013-08-01","caller":"910251415"}]

getVoiceRecording by Cdr ID

input data

task: getVoiceRecording, 
user: USER,
password: PASSWORD,
params: {  cdrId: 999999 }
}

Examples =

HTTP POST =

echo '{"task": "getVoiceRecording", "user": "USER", "password": "PASSWORD", "params": {"cdrId": "4919"}}' | php api.php


HTTP GET

http://localhost/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"cdrId":4919}

getVoiceRecording by Call ID

input data

task: getVoiceRecording,
user: USER,
password: PASSWORD,
params: {  callId: 'XXXXXXXXXXXXXXXXXXXXXX' }}


examples

HTTP POST

echo '{"task": "getVoiceRecording", "user": "USER", "password": "PASSWORD", "params": {"callId": "XXXXXXXXXXXXXXXXXXXXXX"}}' | php api.php

HTTP GET

http://localhost/php/api.php?task=getVoiceRecording&user=USER&password=PASSWORD&params={"callId":"XXXXXXXXXXXXXXXXXXXXXX"}