I'm sure I must be being completely dense somehow, but I can't get JSON::RPC::Client to work as per the documentation on CPAN.
#!/usr/bin/perl use JSON::RPC::Client; use Data::Dumper; my $client = new JSON::RPC::Client; my $url = 'http://9999.9999.9999.9999/api_jsonrpc.php'; my $callobj = { method => 'user.authenticate', params => ["admin","password"] }; print Dumper(ref($callobj)); my $sessionid = $client->call($url, $callobj); if($sessionid) { if ($sessionid->is_error) { print "Error : ", $sessionid->error_message; } else { print $sessionid->result; } } else { print $client->status_line; }
IP, username and password have been substituted for generic ones. I'm trying to connect to the Zabbix API running on a test server. A test PHP script works fine. JSON::RPC::Client sits and complains that I'm not passing it a hash. Running it I get:
$VAR1 = 'HASH'; Not a HASH reference at /usr/local/share/perl/5.10.0/JSON/RPC/Client.p +m line 194.
so I presumably know for sure that $callobj is a hash? I've also tried putting params in the format: params => { username=>"admin", password=>"password" } Again this was to no avail, same error message. line 194 relates to JSON::RPC::Client's returning section, "new" subroutine (194 line starts $content->{error} ):
sub new { my ($class, $obj, $json) = @_; my $content = ( $json || JSON->new->utf8 )->decode( $obj->content +); my $self = bless { jsontext => $obj->content, content => $content, }, $class; $content->{error} ? $self->is_success(0) : $self->is_success(1); $content->{version} ? $self->version(1.1) : $self->version(0) ; $self; }
Help me please perl monks, I'm utterly flummoxed.

In reply to Grappling with JSON::RPC::Client by Garp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.