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