Asterisk 16.4 API

Dear Support/Community
I have one issue in using asterisk version 16.4
I have created one api from an api template and working was good.
Now updated asterisk version from 16.2 to 16.4 and this api isn’t working
as before it was working.
actually behavior of api at asterisk 16.2, is getting remote caller id
of current call from cdr table from database.
but now asterisk 16.4 this api get remote caller id when agent hangup call.

Below is my API File

<?php header('Access-Control-Allow-Origin: http://darewro.com', false); if(!isset($_GET['extention_id'])){ echo 0; exit(); } $extention_id = (int) $_GET['extention_id']; if($extention_id>0){ $servername = "localhost"; $username = "root"; $password = ""; $dbname = "asterisk"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT `cdr_id`, `src` FROM `cdr` WHERE `calltype`=2 AND `disposition`='ANSWERED' AND `dst`='".$extention_id."' ORDER BY `calldate` DESC LIMIT 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo $row["src"]; } } else { echo "No Call"; } }else{ echo 0; exit(); } $conn->close(); ?>

Can you format your code? At first glance it looks like an external script that uses PHP.

This query is where you get the caller id using the src value. CDR record is created when the call is hangup

Dear ambiorixg12
But at Asterisk 16.2 it get live caller id but at Asterisk 16.4 it get caller id of hangup call.
can you help me to how to get live caller id please

Thanks for you response

Dear EkFuderk
Thanks for your kind response.

<?php
header('Access-Control-Allow-Origin: http://darewro.com', false);
if(!isset($_GET['extention_id'])){
	echo 0;
	exit();
	}
$extention_id = (int) $_GET['extention_id'];
if($extention_id>0){
	

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "asterisk";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT `cdr_id`, `src` FROM `cdr` WHERE `calltype`=2 AND `disposition`='ANSWERED' AND `dst`='".$extention_id."' ORDER BY `calldate` DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["src"];
    }
} else {
    echo "No Call";
}
}else{
	echo 0;
	exit();
	}
$conn->close();
?>

If the value is not on the CDR table you can use CDR variables instead of read directly on the CDR https://wiki.asterisk.org/wiki/display/AST/CDR+Variables

Dear sir can you help to put these variables in php api file please. I am very new to asterisk.

Use the $argv array to feed your script from the command line with the Asterisk variables

sir still i am confused.
if you can please add the variables in this php file please

same=>n,Noop( * {CDR(clid)} Caller ID * {CDR(src)} Source * {CDR(dst)} Destination ) same=>n,agi(script.php,{CDR(clid)},${CDR(src)})
then use the $argv array

thanks for your kind support i will check and update you asap

Dear Ambiorixg12,

I have still same issue…
can you help me to edit this php file for getting current caller id on asterisk 16.4

Show me your php script your and your Asterisk dial plan

Dear Sir This is php script which was working well before update to asterisk 16.4

<?php
header('Access-Control-Allow-Origin: http://darewro.com', false);
if(!isset($_GET['extention_id'])){
	echo 0;
	exit();
	}
$extention_id = (int) $_GET['extention_id'];
if($extention_id>0){
	

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "asterisk";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT `cdr_id`, `src` FROM `cdr` WHERE `calltype`=2 AND `disposition`='ANSWERED' AND `dst`='".$extention_id."' ORDER BY `calldate` DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["src"];
    }
} else {
    echo "No Call";
}
}else{
	echo 0;
	exit();
	}
$conn->close();
?>
Dial Plan:



[sip-default]
exten => s,1,NoOp(Guest call to extension S or without DID)
 same => n,Hangup()

exten => _.,1,NoOp(Guest call to DID ${EXTEN})
 same => n,Hangup()

[ext-followme]
exten => FW150,1,NoOp(Follow Me: FW150)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:d)})
 same => n,FollowMe(FW150,${FOLLOWME_OPT})
 same => n,Return()

exten => FW101,1,NoOp(Follow Me: FW101)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW101,${FOLLOWME_OPT})
 same => n,Return()

exten => FW103,1,NoOp(Follow Me: FW103)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW103,${FOLLOWME_OPT})
 same => n,Return()

exten => FW102,1,NoOp(Follow Me: FW102)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW102,${FOLLOWME_OPT})
 same => n,Return()

exten => FW104,1,NoOp(Follow Me: FW104)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW104,${FOLLOWME_OPT})
 same => n,Return()

exten => FW111,1,NoOp(Follow Me: FW111)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW111,${FOLLOWME_OPT})
 same => n,Return()

exten => FW112,1,NoOp(Follow Me: FW112)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW112,${FOLLOWME_OPT})
 same => n,Return()

exten => FW113,1,NoOp(Follow Me: FW113)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW113,${FOLLOWME_OPT})
 same => n,Return()

exten => FW114,1,NoOp(Follow Me: FW114)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW114,${FOLLOWME_OPT})
 same => n,Return()

exten => FW115,1,NoOp(Follow Me: FW115)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW115,${FOLLOWME_OPT})
 same => n,Return()

exten => FW121,1,NoOp(Follow Me: FW121)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW121,${FOLLOWME_OPT})
 same => n,Return()

exten => FW122,1,NoOp(Follow Me: FW122)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW122,${FOLLOWME_OPT})
 same => n,Return()

exten => FW123,1,NoOp(Follow Me: FW123)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW123,${FOLLOWME_OPT})
 same => n,Return()

exten => FW124,1,NoOp(Follow Me: FW124)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW124,${FOLLOWME_OPT})
 same => n,Return()

exten => FW125,1,NoOp(Follow Me: FW125)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW125,${FOLLOWME_OPT})
 same => n,Return()

exten => FW126,1,NoOp(Follow Me: FW126)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW126,${FOLLOWME_OPT})
 same => n,Return()

exten => FW127,1,NoOp(Follow Me: FW127)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW127,${FOLLOWME_OPT})
 same => n,Return()

exten => FW128,1,NoOp(Follow Me: FW128)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW128,${FOLLOWME_OPT})
 same => n,Return()

exten => FW129,1,NoOp(Follow Me: FW129)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW129,${FOLLOWME_OPT})
 same => n,Return()

exten => FW130,1,NoOp(Follow Me: FW130)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW130,${FOLLOWME_OPT})
 same => n,Return()

exten => FW149,1,NoOp(Follow Me: FW149)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW149,${FOLLOWME_OPT})
 same => n,Return()

exten => FW151,1,NoOp(Follow Me: FW151)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW151,${FOLLOWME_OPT})
 same => n,Return()

exten => FW152,1,NoOp(Follow Me: FW152)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW152,${FOLLOWME_OPT})
 same => n,Return()

exten => FW116,1,NoOp(Follow Me: FW116)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW116,${FOLLOWME_OPT})
 same => n,Return()

exten => FW117,1,NoOp(Follow Me: FW117)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW117,${FOLLOWME_OPT})
 same => n,Return()

exten => FW131,1,NoOp(Follow Me: FW131)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW131,${FOLLOWME_OPT})
 same => n,Return()

exten => FW132,1,NoOp(Follow Me: FW132)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW132,${FOLLOWME_OPT})
 same => n,Return()

exten => FW118,1,NoOp(Follow Me: FW118)
 same => n,Set(__O_RING_TIME=30)
 same => n,Set(FOLLOWME_OPT=${IF($["${QUEUE_CALL}"="TRUE"]?N:ns)})
 same => n,FollowMe(FW118,${FOLLOWME_OPT})
 same => n,Return()

[ext-conferences]
exten => 100,1,NoOp(Conference: DarEwro_Conference)
 same => n,Gosub(sub-set-call-vars,app-incoming,1)
 same => n,Answer()
 same => n,ExecIf($["${OVER_WRITTEN_LANG}"!="TRUE"]?Set(CHANNEL(language)=en):)
 same => n,Set(MENU=user_menu)
 same => n,Set(CONFERENCE_PROFILE=user_conf1)
 same => n,Set(COUNTER=1)
 same => n,While($[${COUNTER} < 4])
 same => n,Read(CONFPIN,confbridge-pin,,,3,5)
 same => n,GotoIf($[${CONFPIN}=12345]?confuser)
 same => n,GotoIf($[${CONFPIN}=54321]?confadmin)
 same => n,Playback(conf-invalidpin,skip)
 same => n,Set(COUNTER=$[${COUNTER} + 1])
 same => n,EndWhile()
 same => n,GotoIf($[${COUNTER}>3]?invalid-tries)
 same => n(confuser),Set(CONFBRIDGE(user,admin)=no)
 same => n,Set(CONFBRIDGE(user,marked)=no)
 same => n,Goto(call-conf)
 same => n(confadmin),Set(CONFBRIDGE(user,admin)=yes)
 same => n,Set(CONFBRIDGE(user,marked)=yes)
 same => n,Set(MENU=admin_menu)
 same => n,Set(CONFERENCE_PROFILE=admin_conf1)
 same => n,Goto(call-conf)
 same => n(call-conf),NoOp(Starting Conference)
 same => n,ConfBridge(100,bridge_conf1,${CONFERENCE_PROFILE},${MENU})
 same => n,Hangup()
 same => n(invalid-tries),Playback(conf-invalid,skip)
 same => n,Hangup()

[ext-parking]
include => parking-1-parkedcalls

exten => 700,1,NoOp(Parking Call)
 same => n,Park(parking-1)

exten => _70[1-9],1,NoOp(Slot: ${CALL_DESTINATION})
 same => n,Gosub(sub-parking-lots,s,1(${CALL_DESTINATION},parking-1,parking-1-parkedcalls))

exten => _710,1,NoOp(Slot: ${CALL_DESTINATION})
 same => n,Gosub(sub-parking-lots,s,1(${CALL_DESTINATION},parking-1,parking-1-parkedcalls))

[parking-1-parkedcallstimeout]
exten => s,1,NoOp(Parking Timeout has been reached)
 same => n,Gosub(app-termination,hangup,1)
 same => n,Hangup()

[applications]
;include => app-speedial
;include => app-custom-application
;include => app-custom-destination
;include => app-paging
;include => app-vmgroup
;include => app-queues-priority
include => app-disa
include => app-ivr
;include => app-announcement
;include => app-languages
;include => app-nightmode
;include => app-call-back
;include => app-time-condition
;include => app-scom


[extensions]
include => ext-conferences
include => ext-parking
include => ext-ringgroups
include => ext-queues


[hot-desking-context]
include => global-hints

exten => *80,1,Set(CDR(source)=${CALLERID(num)})
 same => n,Set(CDR(destination)=${EXTEN})
 same => n,NoOp(Hot Desking Feature)
 same => n,Set(__TENANT=8c6785d40f7e83ba)
 same => n,Gosub(sub-hot-desking,s,1)
 same => n,Hangup()

exten => _[-+*#0-9a-zA-Z].,1,Set(CDR(source)=${CALLERID(num)})
 same => n,Set(CDR(destination)=${EXTEN})
 same => n,NoOp(Hot Desking)
 same => n,Set(__TENANT=8c6785d40f7e83ba)
 same => n,Gosub(sub-hot-desking-call,s,1(${EXTEN}))

[cos-all]
include => global-hints
include => cos-all-init


[cos-all-init]
exten => _[-+*#0-9a-zA-Z].,1,NoOp(More than on digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => _[-+*#0-9a-zA-Z],1,NoOp(One Digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => s,1,Set(EXTENSION=${ARG1})
 same => n,NoOp(Dialing ${EXTENSION} from ${CALLERID(num)})
 same => n,Gosub(sub-set-global-vars,s,1(${EXTENSION},parking-1))
 same => n,Gosub(sub-set-call-vars,s,1(8c6785d40f7e83ba,${EXTENSION},1,cos-all,ARS-all))
 same => n,Gosub(sub-construct-cid,s,1)
 same => n,Gosub(set-global-tenant-vars,s,1)
 same => n,NoOp(Check if is an Emergency Call)
 same => n,GotoIf($[${DIALPLAN_EXISTS(emergency-calls,${EXTENSION},1)}=1]?emergency-calls,${EXTENSION},1)
 same => n,Gosub(sub-lockphone-check,s,1)
 same => n,Gosub(sub-local-dialing,s,1)
 same => n,GosubIf($["${CALL_ORIGIN}"="RESTRICTED_IVR_CALL"]?:cos-all-post,${EXTENSION},1)
 same => n,Hangup()

[cos-all-custom]
exten => fake-ext,1,NoOp(Fake extension for generate this context from VitalPBX)

[cos-all-post]
include => all-features-category
include => extensions
include => applications
include => cos-all-custom
include => ARS-all
include => not-allowed-features
include => app-termination

exten => i,1,Goto(invalid-dest-cos,s,1)

[cos-all-trunk]
exten => _[-+*#0-9a-zA-Z].,1,NoOp(Class of Services Trunk: All Permissions)
 same => n,Gosub(sub-check-blacklist,s,1(8c6785d40f7e83ba,${CALLERID(num)}))
 same => n,Gosub(sub-setup-call-type,s,1(incoming))
 same => n,Gosub(sub-set-call-vars,s-incoming,1(${CALLERID(num)},${EXTEN},8c6785d40f7e83ba))
 same => n,Goto(cos-all,${EXTEN},1)
 same => n,Hangup()

[cos-Call-Center-CS]
include => global-hints
include => cos-Call-Center-CS-init


[cos-Call-Center-CS-init]
exten => _[-+*#0-9a-zA-Z].,1,NoOp(More than on digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => _[-+*#0-9a-zA-Z],1,NoOp(One Digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => s,1,Set(EXTENSION=${ARG1})
 same => n,NoOp(Dialing ${EXTENSION} from ${CALLERID(num)})
 same => n,Gosub(sub-set-global-vars,s,1(${EXTENSION},parking-1))
 same => n,Gosub(sub-set-call-vars,s,1(8c6785d40f7e83ba,${EXTENSION},2,cos-Call-Center-CS,ARS-1))
 same => n,Gosub(sub-construct-cid,s,1)
 same => n,Gosub(set-global-tenant-vars,s,1)
 same => n,NoOp(Check if is an Emergency Call)
 same => n,GotoIf($[${DIALPLAN_EXISTS(emergency-calls,${EXTENSION},1)}=1]?emergency-calls,${EXTENSION},1)
 same => n,Gosub(sub-lockphone-check,s,1)
 same => n,Gosub(sub-local-dialing,s,1)
 same => n,GosubIf($["${CALL_ORIGIN}"="RESTRICTED_IVR_CALL"]?:cos-Call-Center-CS-post,${EXTENSION},1)
 same => n,Hangup()

[cos-Call-Center-CS-custom]
exten => fake-ext,1,NoOp(Fake extension for generate this context from VitalPBX)

[cos-Call-Center-CS-post]
include => all-features-category
include => extensions
include => applications
include => cos-Call-Center-CS-custom
include => ARS-1
include => not-allowed-features
include => app-termination

exten => i,1,Goto(invalid-dest-cos,s,1)

[cos-Call-Center-CS-trunk]
exten => _[-+*#0-9a-zA-Z].,1,NoOp(Class of Services Trunk: Call-Center-CS)
 same => n,Gosub(sub-check-blacklist,s,1(8c6785d40f7e83ba,${CALLERID(num)}))
 same => n,Gosub(sub-setup-call-type,s,1(incoming))
 same => n,Gosub(sub-set-call-vars,s-incoming,1(${CALLERID(num)},${EXTEN},8c6785d40f7e83ba))
 same => n,Goto(cos-Call-Center-CS,${EXTEN},1)
 same => n,Hangup()

[set-global-tenant-vars]
exten => s,1,NoOp(Setting Global Vars for vitalpbx Tenant)
 same => n,Set(__TENANT_PATH=8c6785d40f7e83ba)
 same => n,Set(__TENANT_PREFIX=)
 same => n,Set(__QUEUE_AGENTS_CONTEXT=queue-call-to-agents)
 same => n,Set(__FOLLOWME_CONTEXT=ext-followme)
 same => n,Set(__HINTS_CONTEXT=extension-hints)
 same => n,Return()

[all-features-category]
include => feature-account_code
include => feature-boss_secretary
include => feature-attended_transfer
include => feature-one_touch_rec
include => feature-auth_code
include => feature-add_num_blacklist
include => feature-add_last_caller_blacklist
include => feature-remove_number_blacklist
include => feature-blind_transfer
include => feature-cancel_cc
include => feature-request_cc
include => feature-set_cfb_number
include => feature-toggle_cfb
include => feature-set_cfu_number
include => feature-toggle_cfu
include => feature-toggle_cfn
include => feature-set_cfn_number
;include => feature-spy_random_chn
include => feature-change_ext_pwd
include => feature-clear_all_diversions
include => feature-cust_recording
include => feature-dictation_services
include => feature-direct_vm
include => feature-direct_pickup
include => feature-disconnect_call
include => feature-dnd
include => feature-echo_test
include => feature-follow_me
include => feature-hot_desking
include => feature-dial_by_name_dir
include => feature-lock_unlock_phone
include => feature-nm_all
include => feature-park_call
include => feature-personal_assistant
include => feature-pickup_group
include => feature-rec_msg_pa
include => feature-reminder
include => feature-remote_substitution
include => feature-remote_vm
;include => feature-remote_wakeup_call
include => feature-say_date_time
include => feature-simulate_incoming_call
include => feature-speak_last_number
include => feature-speak_ext_number
;include => feature-spy_extension
;include => feature-spy_ext_whisper
include => feature-add_remove_queue_agent
include => feature-pause_unpause_queue_agent
include => feature-request_wakeup_call
include => feature-toggle_cfi
include => feature-set_cfi_number
include => feature-queues_login_logout
include => feature-queues-pause-unpause
include => feature-send_vm_msg
;include => feature-spy_ext_barge
include => feature-paging_and_intercom


[DRR-1]
exten => _03XXXXXXXXX,1,Playback(the-number-u-dialed&is&privacy-blocked)
 same => n,Hangup()
 same => n,Goto(${ARS},${EXTEN},1)

[ext-ringgroups]
exten => i,1,Goto(invalid-dest,s,1)

[queue-call-to-agents]
exten => _[-+*#0-9].,1,NoOp(More than on digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => _[-+*#0-9],1,NoOp(One Digit pattern)
 same => n,Gosub(s,1(${EXTEN}))

exten => s,1,Set(EXTENSION=${ARG1})
 same => n,Set(TENANT=8c6785d40f7e83ba)
 same => n,Set(COS=${DB(${TENANT}/extensions/${EXTENSION}/context)})
 same => n,NoOp(Dialing Agent ${EXTENSION} from ${CALLERID(num)})
 same => n,Gosub(${COS},${EXTENSION},1)
 same => n,Hangup()

[ext-queues]
exten => 199,1,NoOp(Queue: Darewro-Call-Queue)
 same => n,Set(__QUEUE_CALL=TRUE)
 same => n,Gosub(sub-set-moh,s,1(moh2,YES))
 same => n,Set(__QUEUE_NUMBER=199)
 same => n,Gosub(sub-set-call-vars,app-incoming,1)
 same => n(qconnect),NoOp(Connecting to Queue)
 same => n,Answer()
 same => n,NoCDR()
 same => n,Queue(Q199,c,,,)
 same => n,ResetCDR(ve)
 same => n,NoOp(Queue Status: ${QUEUESTATUS})
 same => n,Set(__QUEUE_CALL=FALSE)
 same => n,GotoIf($["${QUEUESTATUS}"="CONTINUE"]?app-termination,hangup,1)
 same => n,Goto(app-termination,hangup,1)
 same => n,Hangup()

exten => h,1,NoOp(Ending Queue Call)
 same => n,Hangup()

[trk-1]
exten => _[+*#0-9].,1,NoOp(Trunk: NayaTel SIP Trunk)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing,${ICALL}))
 same => n(trk-conf),NoOp(Configuring Trunk Parameters)
 same => n,Set(CHANNEL(musicclass)=default)
 same => n,Set(CALLERID(all)="" <7241724>)
 same => n,Set(__TRKDIALOPTIONS=r)
 same => n,Set(ORIGINATOR=${IF($["${CALL_ORIGIN}"="diversions"]?${DIVERSION_ORIGIN}:${CALL_SOURCE})})
 same => n,Set(RING_TIME=${IF($["X${O_RING_TIME}X"="XX"]?60:${O_RING_TIME})})
 same => n,Set(CALLED=${EXTEN})
 same => n,Dial(SIP/nayatel-sip-trunk/${EXTEN},${RING_TIME},${TRKDIALOPTIONS}${EXTRA_DIAL_OPTIONS}U(sub-call-recording^${TENANT}^${ORIGINATOR}^${EXTEN}^no))
 same => n(after_dial),NoOp(After Dial)
 same => n,GotoIf($["${ARG1}"="from-trk-grp"]?come-back)
 same => n,Hangup()
 same => n(come-back),Return()

exten => h,1,Gosub(dynamic-routing-out,s,1(${ORIGINATOR},${CALLED},${DIALSTATUS},1))
 same => n,Hangup()

[trk-1-in]
exten => _[+*#0-9A-Za-z].,1,NoOp(Incoming call through: NayaTel SIP Trunk)
 same => n,Set(DID=${EXTEN})
 same => n,Goto(default-trunk,${DID},1)

[trk-group-1]
exten => _03XXXXXXXXX,1,NoOp(Mobile_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-1,1)

exten => _0XXXXXXXXX,1,NoOp(Mobile_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-1,1)

exten => _XXXXXXX,1,NoOp(Mobile_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-1,1)

exten => _+923XXXXXXXXX,1,NoOp(Mobile_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=0${EXTEN:3})
 same => n,Goto(s-1,1)

exten => _00923XXXXXXXXX,1,NoOp(Mobile_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=0${EXTEN:4})
 same => n,Goto(s-1,1)

exten => s-1,1,Gosub(sub-construct-cid,s-external,1)
 same => n(dial-trk-1),Gosub(trk-1,${DNID},1(from-trk-grp))
 same => n,NoOp(Hangup Cause: ${HANGUPCAUSE}, Dial Status: ${DIALSTATUS})
 same => n(finish),NoCDR()
 same => n,GotoIf($["${CALL_ORIGIN}"="ring-group"]?end_call)
 same => n,Gosub(sub-hangup-cause,s,1(${HANGUPCAUSE}))
 same => n(end_call),Hangup()

exten => h,1,NoOp(Ending Outbound Call)
 same => n,Hangup()

[trk-group-2]
exten => _0XXXXXXXXX,1,NoOp(National_OutBound_Route)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-2,1)

exten => _XXXXXXX,1,NoOp(National_OutBound_Route)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-2,1)

exten => s-2,1,Gosub(sub-construct-cid,s-external,1)
 same => n(dial-trk-1),Gosub(trk-1,${DNID},1(from-trk-grp))
 same => n,NoOp(Hangup Cause: ${HANGUPCAUSE}, Dial Status: ${DIALSTATUS})
 same => n(finish),NoCDR()
 same => n,GotoIf($["${CALL_ORIGIN}"="ring-group"]?end_call)
 same => n,Gosub(sub-hangup-cause,s,1(${HANGUPCAUSE}))
 same => n(end_call),Hangup()

exten => h,1,NoOp(Ending Outbound Call)
 same => n,Hangup()

[trk-group-3]
exten => _XXXXXXX,1,NoOp(LandLine_OutBoundRoute)
 same => n,Gosub(sub-setup-call-type,s,1(outgoing))
 same => n(dial-trunks),NoOp(Start to Dial Trunks)
 same => n,Set(DNID=${EXTEN:0})
 same => n,Goto(s-3,1)

exten => s-3,1,Gosub(sub-construct-cid,s-external,1)
 same => n(dial-trk-1),Gosub(trk-1,${DNID},1(from-trk-grp))
 same => n,NoOp(Hangup Cause: ${HANGUPCAUSE}, Dial Status: ${DIALSTATUS})
 same => n(finish),NoCDR()
 same => n,GotoIf($["${CALL_ORIGIN}"="ring-group"]?end_call)
 same => n,Gosub(sub-hangup-cause,s,1(${HANGUPCAUSE}))
 same => n(end_call),Hangup()

exten => h,1,NoOp(Ending Outbound Call)
 same => n,Hangup()

[ARS-all]
include => trk-group-1
include => trk-group-2
include => trk-group-3


[ARS-1]
exten => i,1,Goto(invalid-dest,s,1)

[ARS-2]
exten => i,1,Goto(invalid-dest,s,1)

[default-trunk]
exten => _[+*#0-9A-Za-z].,1,Gosub(set-global-tenant-vars,s,1)
 same => n,Gosub(sub-check-blacklist,s,1(8c6785d40f7e83ba,${CALLERID(num)}))
 same => n,Gosub(sub-setup-call-type,s,1(incoming))
 same => n,Gosub(dynamic-routing-in,s,1(${CALLERID(num)}))
 same => n,Goto(incoming-calls,${EXTEN},1)

[incoming-calls]
exten => _7241724,1,NoOp(INBOUND_ROUTE: NayaTel)
 same => n,Set(CHANNEL(language)=en)
 same => n,Set(CHANNEL(musicclass)=default)
 same => n,Gosub(sub-set-call-vars,s-incoming,1(${CALLERID(num)},${EXTEN},8c6785d40f7e83ba))
 same => n,Set(ICALL=yes)
 same => n,Goto(ext-queues,199,1)
 same => n,Hangup()

exten => fax,1,NoOp(Fax Detected)
 same => n,Set(FAXOPT(faxdetect)=no)
 same => n,Goto(${FAX_DEST_CONT},${FAX_DEST_EXT},${FAX_DEST_PRIO})

exten => i,1,NoCDR()
 same => n,Goto(invalid-dest,s,1)

exten => pm-failed,1,NoCDR()
 same => n,Answer()
 same => n,Playback(sorry&vm-goodbye,skip)
 same => n,Hangup()

[app-disa]
exten => DISA-1,1,NoOp(DISA: Testing-DISA)
 same => n,Authenticate(1234)
 same => n,Playback(pls-entr-num-uwish2-call&astcc-followed-by-pound)
 same => n,Set(TIMEOUT(digit)=5)
 same => n,Set(TIMEOUT(response)=10)
 same => n,DISA(no-password,cos-all,"${CALLERID(name)}" <${CALLERID(number)}>)
 same => n,Hangup()

exten => i,1,NoCDR()
 same => n,Goto(invalid-dest,s,1)

exten => t,1,NoCDR()
 same => n,Goto(timeout-reached,s,1)

[app-ivr]
exten => IVR-1,1,Goto(IVR-1,s,1)

[IVR-1]
exten => s,1,NoOp(IVR: Test)
 same => n,Set(INVALIDATTEMPTS=0)
 same => n,Set(TIMEOUTATTEMPTS=0)
 same => n,Set(TIMEOUT(digit)=2)
 same => n,Set(TIMEOUT(response)=10)
 same => n,Answer()
 same => n(begin),NoOp(IVR Menu Begin)
 same => n,BackGround(welcome)
 same => n(retry),NoOp(IVR Retry Section)
 same => n,WaitExten(10)

exten => 1,1,NoOp(Option 1 has been pressed)
 same => n,Goto(cos-all,150,1)

exten => #,1,Hangup()

exten => *,1,Goto(s,begin)

exten => t,1,Set(TIMEOUTATTEMPTS=$[${TIMEOUTATTEMPTS}+1])
 same => n,GotoIf($[${TIMEOUTATTEMPTS}>=3]?timeout)
 same => n,BackGround(option-is-invalid)
 same => n,Goto(s,retry)
 same => n(timeout),BackGround(sorry-youre-having-problems&vm-goodbye)
 same => n,Goto(app-termination,hangup,1)

exten => i,1,Set(INVALIDATTEMPTS=$[${INVALIDATTEMPTS}+1])
 same => n,GotoIf($[${INVALIDATTEMPTS}>=3]?invalid)
 same => n,BackGround(option-is-invalid)
 same => n,Goto(s,retry)
 same => n(invalid),BackGround(sorry-youre-having-problems&vm-goodbye)
 same => n,Goto(cos-all,150,1)

[ivr-only-extensions]
exten => _[*#+0-9].,1,Set(__CALL_ORIGIN=RESTRICTED_IVR_CALL)
 same => n,Goto(cos-all,${EXTEN},1)
 same => n,Hangup()

[TC-1]
exten => s,1,NoOp(Time Group: DDS_Working_Time)
 same => n,Set(__TGMATCH=0)
 same => n,GotoIfTime(09:00-23:59,*,*,*,?match:)
 same => n,Return()
 same => n(match),Set(__TGMATCH=1)
 same => n,Return()

[TC-2]
exten => s,1,NoOp(Time Group: DDS_Off_Time)
 same => n,Set(__TGMATCH=0)
 same => n,GotoIfTime(00:05-08:59,*,*,*,?match:)
 same => n,Return()
 same => n(match),Set(__TGMATCH=1)
 same => n,Return()

[sub-dnd-prompt]
exten => s,1,NoOp(Playing dnd prompt)
 same => n,Playback(the-number-u-dialed&has&do-not-disturb&enabled&silence/1&please-try-again-later)
 same => n,Return()
 same => n,Hangup()

[sub-blacklisted-prompt]
exten => s,1,NoOp(Playing blacklisted prompt)
 same => n,Playback(privacy-you-are-blacklisted&goodbye)
 same => n,Return()
 same => n,Hangup()



The final result of your script is to echo the CDR src value, where in your dial plan is the interaction of the php script and Asterisk ?

I see you just pass the $_GET[‘extention_id’] value as parameter to your web php script, but still cant see where is the interaction betwen Asterisk dial plan and your script

So sir what is the solution for it. Please help me.
So how i can get work properly please guide me

Looks like you dont know what you re doing, I can help you but I cant don your job. On your fist post you said

“actually behavior of api at asterisk 16.2, is getting remote caller id
of current call from cdr table from database.
but now asterisk 16.4 this api get remote caller id when agent hangup call…”

What it is current output of your php script now ?

What it is next step after get the CID because I see you only echo $row[“src”];

Dear sir.
Sorry for inconvenience…
At asterisk 16.0 my php was getting remote Caller-ID of current call but after updated it to 16.4, now my php gets remote Caller-ID after hangups call.
I will explain in detail. At asterisk 16.0 when call reached to queue and attend by an extension(agent) so using php we were getting remote Caller-ID of this current call attend by an extension.
After updated to asterisk 16.4 when a call attend by extension so php doesn’t get remote Caller-ID of current call. After hangup the call, php gets remote Caller-ID.

Below is the output of our php

http://10.0.1.241/get_call_number.php?extention_id=150
Using this to get remote Caller-ID from specific extension

Callerd ID of the caller after connect the call with an Agent, I think can be accessed using a Gosub and a channel variable. using the CDR and the src value field it is posible that it is only avaiable after hangup, I would need to make to give you an example, but I dont have queue on my system now