Hello good morning I made a connection with a WebService with PHP through the xml-rpc library and brought some data. Now I am trying to fetch only the i_account and connect_time fields from the array or directly from the query but it is not working for me either way.
I share and hope you can support me.
<?php
include 'lib/xmlrpc/xmlrpc.inc';
$params = array(new xmlrpcval(array(
"i_account" => new xmlrpcval("2893", "int"),
"start_date" => new xmlrpcval("00:00:00.000 GMT Mon Mar 09 2020", "string"),
"end_date" => new xmlrpcval("23:59:59.000 GMT Mon Mar 09 2020", "string"),
"limit" => new xmlrpcval("1", "int"),
), 'struct'));
$msg = new xmlrpcmsg('getAccountCDRs', $params);
/* replace here URL and credentials to access to the API */
$cli = new xmlrpc_client('https://sip.serv.net.mx/xmlapi/xmlapi');
$cli->setSSLVerifyPeer(false);
$cli->setSSLVerifyHost(false);
$cli->setCredentials('ABACOM', 'contraseña', CURLAUTH_DIGEST);
$r = $cli->send($msg); /* 20 seconds timeout */
if ($r->faultCode()) {
error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
return false;
}
print_r($r);
?>
Query result
xmlrpcresp Object ( [val] => xmlrpcval Object ( [me] => Array ( [struct] => Array ( [cdrs] => xmlrpcval Object ( [me] => Array ( [array] => Array ( [0] => xmlrpcval Object ( [me] => Array ( [struct] => Array ( [accessibility_cost] => xmlrpcval Object ( [me] => Array ( [double] => 0 ) [mytype] => 1 [_php_class] => ) [protocol] => xmlrpcval Object ( [me] => Array ( [string] => SIP ) [mytype] => 1 [_php_class] => ) [connect_time] => xmlrpcval Object ( [me] => Array ( [string] => 23:23:39.000 GMT Mon Mar 9 2020 ) [mytype] => 1 [_php_class] => ) [media_timeout_correction] => xmlrpcval Object ( [me] => Array ( [double] => 0 ) [mytype] => 1 [_php_class] => ) [lrn_cld] => xmlrpcval Object ( [me] => Array ( [string] => LRN_FIJO1251475511035395 ) [mytype] => 1 [_php_class] => ) [disconnect_time] => xmlrpcval Object ( [me] => Array ( [string] => 23:26:39.000 GMT Mon Mar 9 2020 ) [mytype] => 1 [_php_class] => ) [prefix] => xmlrpcval Object ( [me] => Array ( [string] => LRN_FIJO ) [mytype] => 1 [_php_class] => ) [cost] => xmlrpcval Object ( [me] => Array ( [double] => 0.6 ) [mytype] => 1 [_php_class] => ) [result] => xmlrpcval Object ( [me] => Array ( [int] => 0 ) [mytype] => 1 [_php_class] => ) [duration] => xmlrpcval Object ( [me] => Array ( [double] => 179.532800493 ) [mytype] => 1 [_php_class] => ) [interval_1] => xmlrpcval Object ( [me] => Array ( [int] => 60 ) [mytype] => 1 [_php_class] => ) [cli] => xmlrpcval Object ( [me] => Array ( [string] => 4421611002 ) [mytype] => 1 [_php_class] => ) [pdd1xx] => xmlrpcval Object ( [me] => Array ( [double] => 0.169372445 ) [mytype] => 1 [_php_class] => ) [cld] => xmlrpcval Object ( [me] => Array ( [string] => NN5511035395 ) [mytype] => 1 [_php_class] => ) [i_cdr] => xmlrpcval Object ( [me] => Array ( [int] => 1651106169 ) [mytype] => 1 [_php_class] => ) [call_id] => xmlrpcval Object ( [me] => Array ( [string] => [email protected] ) [mytype] => 1 [_php_class] => ) [delay] => xmlrpcval Object ( [me] => Array ( [double] => 13 ) [mytype] => 1 [_php_class] => ) [cld_in] => xmlrpcval Object ( [me] => Array ( [string] => 5511035395 ) [mytype] => 1 [_php_class] => ) [i_call] => xmlrpcval Object ( [me] => Array ( [int] => 1651104264 ) [mytype] => 1 [_php_class] => ) [free_seconds] => xmlrpcval Object ( [me] => Array ( [int] => 0 ) [mytype] => 1 [_php_class] => ) [post_call_surcharge] => xmlrpcval Object ( [me] => Array ( [double] => 0 ) [mytype] => 1 [_php_class] => ) [i_account] => xmlrpcval Object ( [me] => Array ( [int] => 2893 ) [mytype] => 1 [_php_class] => ) [price_n] => xmlrpcval Object ( [me] => Array ( [double] => 0.2 ) [mytype] => 1 [_php_class] => ) [grace_period] => xmlrpcval Object ( [me] => Array ( [int] => 0 ) [mytype] => 1 [_php_class] => ) [description] => xmlrpcval Object ( [me] => Array ( [string] => Numero Nacional ) [mytype] => 1 [_php_class] => ) [interval_n] => xmlrpcval Object ( [me] => Array ( [int] => 60 ) [mytype] => 1 [_php_class] => ) [area_name] => xmlrpcval Object ( [me] => Array ( [null] => ) [mytype] => 1 [_php_class] => ) [lrn_cli] => xmlrpcval Object ( [me] => Array ( [null] => ) [mytype] => 1 [_php_class] => ) [connect_fee] => xmlrpcval Object ( [me] => Array ( [double] => 0 ) [mytype] => 1 [_php_class] => ) [remote_party_id] => xmlrpcval Object ( [me] => Array ( [null] => ) [mytype] => 1 [_php_class] => ) [release_source] => xmlrpcval Object ( [me] => Array ( [string] => callee ) [mytype] => 1 [_php_class] => ) [plan_duration] => xmlrpcval Object ( [me] => Array ( [double] => 0 ) [mytype] => 1 [_php_class] => ) [price_1] => xmlrpcval Object ( [me] => Array ( [double] => 0.2 ) [mytype] => 1 [_php_class] => ) [lrn_cli_in] => xmlrpcval Object ( [me] => Array ( [null] => ) [mytype] => 1 [_php_class] => ) [cli_in] => xmlrpcval Object ( [me] => Array ( [string] => 4421611002 ) [mytype] => 1 [_php_class] => ) [billed_duration] => xmlrpcval Object ( [me] => Array ( [double] => 180 ) [mytype] => 1 [_php_class] => ) [country] => xmlrpcval Object ( [me] => Array ( [string] => MEXICO ) [mytype] => 1 [_php_class] => ) [i_protocol] => xmlrpcval Object ( [me] => Array ( [int] => 1 ) [mytype] => 1 [_php_class] => ) [conn_proc_time] => xmlrpcval Object ( [me] => Array ( [double] => 0.016501597 ) [mytype] => 1 [_php_class] => ) [p_asserted_id] => xmlrpcval Object ( [me] => Array ( [null] => ) [mytype] => 1 [_php_class] => ) [user_agent] => xmlrpcval Object ( [me] => Array ( [string] => Abacom IPPBX v.3.0 ) [mytype] => 1 [_php_class] => ) [lrn_cld_in] => xmlrpcval Object ( [me] => Array ( [string] => FIJO1251475511035395 ) [mytype] => 1 [_php_class] => ) [remote_ip] => xmlrpcval Object ( [me] => Array ( [string] => 201.158.0.30 ) [mytype] => 1 [_php_class] => ) ) ) [mytype] => 3 [_php_class] => ) ) ) [mytype] => 2 [_php_class] => ) [result] => xmlrpcval Object ( [me] => Array ( [string] => OK ) [mytype] => 1 [_php_class] => ) ) ) [mytype] => 3 [_php_class] => ) [valtyp] => xmlrpcvals [errno] => 0 [errstr] => [payload] => [hdrs] => Array ( [date] => Fri, 13 Mar 2020 15:50:02 GMT [server] => Apache/2.4.35 (FreeBSD) OpenSSL/1.0.2k-freebsd mod_wsgi/4.6.4 Python/2.7 [vary] => Accept-Encoding [content-encoding] => gzip [connection] => close [transfer-encoding] => chunked [content-type] => text/xml ) [_cookies] => Array ( ) [content_type] => text/xml [raw_data] => HTTP/1.1 401 Unauthorized Date: Fri, 13 Mar 2020 15:50:02 GMT Server: Apache/2.4.35 (FreeBSD) OpenSSL/1.0.2k-freebsd mod_wsgi/4.6.4 Python/2.7 WWW-Authenticate: Digest nonce="486b3e04157198c76d28de83cb1bfe55", opaque="c7ac917793ddfb6c39cf6e08e521bffb", realm="XML API", qop="auth" Vary: Accept-Encoding Content-Encoding: gzip Connection: close Transfer-Encoding: chunked Content-Type: text/plain; charset=utf-8 HTTP/1.1 200 OK Date: Fri, 13 Mar 2020 15:50:02 GMT Server: Apache/2.4.35 (FreeBSD) OpenSSL/1.0.2k-freebsd mod_wsgi/4.6.4 Python/2.7 Vary: Accept-Encoding Content-Encoding: gzip Connection: close Transfer-Encoding: chunked Content-Type: text/xml cdrs accessibility_cost 0.0 protocol SIP connect_time 23:23:39.000 GMT Mon Mar 9 2020 media_timeout_correction 0.0 lrn_cld LRN_FIJO1251475511035395 disconnect_time 23:26:39.000 GMT Mon Mar 9 2020 prefix LRN_FIJO cost 0.6 result 0 duration 179.532800493 interval_1 60 cli 4421611002 pdd1xx 0.169372445 cld NN5511035395 i_cdr 1651106169 call_id [email protected] delay 13.0 cld_in 5511035395 i_call 1651104264 free_seconds 0 post_call_surcharge 0.0 i_account 2893 price_n 0.2 grace_period 0 description Numero Nacional interval_n 60 area_name lrn_cli connect_fee 0.0 remote_party_id release_source callee plan_duration 0.0 price_1 0.2 lrn_cli_in cli_in 4421611002 billed_duration 180.0 country MEXICO i_protocol 1 conn_proc_time 0.016501597 p_asserted_id user_agent Abacom IPPBX v.3.0 lrn_cld_in FIJO1251475511035395 remote_ip 201.158.0.30 result OK )
Following the structure, with
->
for object properties and the key for arrays:Y: