Hello,
On 14.03.23 14:08, Benoit Panizzon wrote:
Hi Volker
An Example by which I query a profile counter:
curl -X POST
http://VoiceSwitch:8080/RPC -H 'Content-Type: application/json' -d
'{"jsonrpc": "2.0", "method":
"dlg.profile_get_size", "params" : ["channels-inuse",
"Customer-XXXX"], "id": 1}'
I think, with jsonrpc 2.0 you could pass an array of named parameters,
but I also struggled with that, just passing an array of parameters in
the right order did it for me.
Perl Snippel I just had at hand while elaborating how to use the
output and using the JSON::RPC2::Client and LWP::UserAgent modules.
my $ua = LWP::UserAgent->new();
my $h = HTTP::Headers->new(
Content_Type => 'application/json'
);
my $client = JSON::RPC2::Client->new();
[...]
$method = "ul.dump";
@params = ();
($json_request, $call) = $client->call($method, @params);
$req = HTTP::Request->new('POST', $reguri . $kamapi, $h, $json_request);
$res = $ua->request($req);
print "=== KAM RPC: $method ===\n";
#print $res->decoded_content;
print "\n";
my $ul = decode_json($res->decoded_content);
#print Dumper($ul);
#print
Dumper($ul->{'result'}->{'Domains'}[0]->{'Domain'});
my @aors =
@{$ul->{'result'}->{'Domains'}[0]->{'Domain'}->{'AoRs'}};
foreach my $aor (@aors) {
print "======== AOR [$aor->{'Info'}->{'AoR'}]
=========\n";
my @contacts = @{$aor->{'Info'}->{'Contacts'}};
foreach my $contact (@contacts) {
print "\t == contact ==\n";
print
"\tAddress:\t$contact->{'Contact'}->{'Address'}\n";
print
"\tExpires:\t$contact->{'Contact'}->{'Expires'}\n";
print "\tUser
Agent:\t$contact->{'Contact'}->{'User-Agent'}\n";
}
}
the parameters have to be provided as positional values in an array --
practically the order matters. That's because the RPC commands are
implementer independent of the transport and command format, it is the
same code executed for binrpc, jsonrpc and xmlrpc. jsonrpc specs allow
named parameters, but the binrpc, which was implemented in first phase,
does not. I am not sure if the xmlrpc can have named parameters.
If you want to provide names to the parameters when sending the command,
it should work with jsonrpcs module, but the names are only aesthetical,
the position of the values is relevant. You can look at the readme of
the jsonrpcs module for some examples of jsonrpcs commands.
Cheers,
Daniel
--
Daniel-Constantin Mierla --
www.asipto.com
www.twitter.com/miconda --
www.linkedin.com/in/miconda
Kamailio World Conference - June 5-7, 2023 -
www.kamailioworld.com
Kamailio Advanced Training - Online - March 27-30, 2023 -
www.asipto.com