Ad Widget

Collapse

help javascript api

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • checifaccioqua?
    Junior Member
    • Mar 2011
    • 14

    #1

    help javascript api

    HI,
    first sorry for my bad inglish........!!!

    This is my problem....I'm not able to connect zabbix api. I followed this code(previosly posted on this forum=>http://www.zabbix.com/forum/showthre...t=14048&page=2)

    Code:
    <HTML>
    <script type="text/javascript">
    
    var the_object;
    var http_request = new XMLHttpRequest();
    var jsonrpc = {'jsonrpc': '2.0','method': 'user.authenticate','params': {'user': 'nome', 'password': 'nome'},'id': 1};
    http_request.open( "POST", '<zabbix_server_path>/zabbix/api_jsonrpc.php', true );
    http_request.setRequestHeader('Content-Type', 'application/json-rpc');
    http_request.send(jsonrpc);
    http_request.onreadystatechange = function () {
        if ( http_request.readyState == 4 ) {
            if ( http_request.status == 200 ) {
                the_object = eval( "(" + http_request.responseText + ")" );
                    document.getElementById("zone").innerHTML = http_request.responseText;
            } else {
                alert( "There was a problem with the URL." );
            }
            http_request = null;
        }
    };
    
    </script>
    <div id="zone"></div>
    </HTML>
    I create a zabbix user with api access but don't work!!!! Please help me!!!!!!!!!!!!!!!!!!!
  • Aly
    ZABBIX developer
    • May 2007
    • 1126

    #2
    Code:
    http_request.open( "POST", '<zabbix_server_path>/zabbix/api_jsonrpc.php', true );
    Make shore that specified URL is correct.

    What exactly XHR returns?
    Zabbix | ex GUI developer

    Comment

    • checifaccioqua?
      Junior Member
      • Mar 2011
      • 14

      #3
      Yes, i'm sure! Zabbix's installation folder are

      /etc/zabbix_*.conf (configuration file)
      /var/www/http/zabbix/* (web interface)

      Code:
       if ( http_request.readyState == 4 )
      Is ok! responde 4

      Code:
      if ( http_request.status == 200 )
      The problem is here, it responde 412 and print the alert messg

      Code:
      alert( "There was a problem with the URL." )
      thanks a lot for help!
      Last edited by checifaccioqua?; 08-03-2011, 14:13. Reason: Wrong code

      Comment

      • Aly
        ZABBIX developer
        • May 2007
        • 1126

        #4
        Try it like that:
        Code:
        var jsonrpc = "{'jsonrpc': '2.0','method': 'user.authenticate','params': {'user': 'nome', 'password': 'nome'},'id': 1}";
        Zabbix | ex GUI developer

        Comment

        • checifaccioqua?
          Junior Member
          • Mar 2011
          • 14

          #5
          Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!! Stupid problem!!!!! Thanks a lot!!!

          Comment

          • stefano.chiesa@wki.it
            Junior Member
            • May 2011
            • 1

            #6
            Hello all.
            I'm trying to use API but when I send the request:

            { 'jsonrpc':'2.0','method':'user.authenticate','para ms':{ 'user':'apiuser', 'password':'apipass'},'id':2}

            I receive:

            application/json-rpc{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}

            Is it a command error or a server error?
            Where am I wrong?

            Thanks in advance.
            Stefano.

            Comment

            • checifaccioqua?
              Junior Member
              • Mar 2011
              • 14

              #7
              Guarda bene params come รจ scritto...ciao!

              Comment

              Working...