Ad Widget

Collapse

Zabbix API always returns Invalid JSON

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jarne St
    Member
    • Sep 2019
    • 63

    #1

    Zabbix API always returns Invalid JSON

    Hello

    When I try to login to the Zabbix API I always get an error.
    I try to call the user.login method but somehow I always get "Invalid JSON. An error occurred on the server while parsing the JSON text."
    This is the command that I use:
    Code:
    curl -i -X POST -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":null,"id":1}' http://172.27.0.162/zabbix/api_jsonrpc.php
    This is the respone that I get:
    Code:
    {"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}
    If I format these JSON in a JSON-formatter it seems to be valid, but somehow the server don't understand it.
    I tried to omit the auth parameter but it didn't change anything.
    I changed user.login with user.authenticate but without success.

    Are there any logs on the server where I can see which methods are used and how the parsed data looks like?
    Or does anyone see what I do wrong?

    I am using zabbix_server version 4.0.13 with Apache version 2.4.29.
    My server runs on Ubuntu version 18.04.3 LTS.

    Thank you for any help!
  • valentins.grins
    Member
    • Nov 2019
    • 38

    #2
    Hello,

    Please try to get the API version with command

    Code:
    curl -i -X POST -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"apiinfo.version","params":[],"id":1}' http://192.168.56.103/api_jsonrpc.php
    You can also try to execute your command with "-lrpc=trace" at the end, maybe it will give some additional information.

    Comment

    • Jarne St
      Member
      • Sep 2019
      • 63

      #3
      If I run that command I get also Invalid JSON.

      Output:
      Code:
      {"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}

      Comment

      • Jarne St
        Member
        • Sep 2019
        • 63

        #4
        I have another update.

        If I use Postman to send the request it is successful but with curl it fails. (I have used exact the same JSON and headers).

        Now I am very curios: what is happening with the "Postman request" and what with the "curl request"?
        Zabbix must do something with curl that causes an error. But I don't see anything wrong with my command?
        What is happening with the "curl request"?

        Comment

        • valentins.grins
          Member
          • Nov 2019
          • 38

          #5
          Have you tried to run it with -lrpc=trace parameters? It may give some additional information.

          If i do command you provided in initial post to Zabbix 4.0.14 i don't have any issues.

          curl is just a client tool that sends data to zabbix. Seems that there is something wrong with formatting.

          Comment

          • valentins.grins
            Member
            • Nov 2019
            • 38

            #6
            Can you please try following two commands and let us know the results:

            Code:
            curl -i -X POST -H "Content-Type:application/json" --data-binary '{"jsonrpc":"2.0","method":"apiinfo.version","params":[],"id":1}' [URL]http://172.27.0.162/zabbix/[/URL]api_jsonrpc.php -lrpc=trace
            Code:
            curl -i -X POST -H "Content-Type:application/json" --data-ascii '{"jsonrpc":"2.0","method":"apiinfo.version","params":[],"id":1}' [URL]http://172.27.0.162/zabbix/[/URL]api_jsonrpc.php -lrpc=trace

            Comment

            • Jarne St
              Member
              • Sep 2019
              • 63

              #7
              I figured it out!
              After I debugged the command with the --trace parameter I saw what the problem was.
              My double quotes where gone and the single quotes where unnecessary.

              My command looks like this and it worked:
              Code:
              curl -H "Content-Type:application/json" -d {\"jsonrpc\":\"2.0\",\"method\":\"user.login\",\"params\":{\"user\":\"Admin\",\"password\":\"zabbix\"},\"auth\":null,\"id\":0} http://172.27.0.162/zabbix/api_jsonrpc.php --trace test3.txt

              Comment

              • Laurie814
                Junior Member
                • Nov 2019
                • 1

                #8
                Originally posted by Jarne St
                I figured it out!
                After I debugged the command with the --trace parameter I saw what the problem was.
                My double quotes where gone and the single quotes where unnecessary.

                My command looks like this and it worked:
                Code:
                curl -H "Content-Type:application/json" -d {\"jsonrpc\":\"2.0\",\"method\":\"user.login\",\"params\":{\"user\":\"Admin\",\"password\":\"zabbix\"},\"auth\":null,\"id\":0} http://172.27.0.162/zabbix/api_jsonrpc.php --trace test3.txt
                If i do command you provided in initial post to Zabbix 4.0.14 i don't have any issues.

                curl is just a client tool that sends data to zabbix. Seems that there is something wrong with formatting.

                Comment

                • chhail.bihari
                  Junior Member
                  • Aug 2022
                  • 1

                  #9
                  I am unable to get network data from widows system. Please find the below screenshot.Click image for larger version

Name:	Screenshot_20220803_171635.png
Views:	7932
Size:	115.9 KB
ID:	449202

                  Comment

                  • pradeepmp
                    Junior Member
                    • Aug 2023
                    • 19

                    #10
                    hello, I am using zabbix 6.4.1 and grafana 10. i get error Invalid params. Invalid parameter "/": unexpected parameter "user". while connecting to zabbix server.

                    Comment

                    • vijayk
                      Senior Member
                      • May 2023
                      • 305

                      #11
                      Originally posted by pradeepmp
                      hello, I am using zabbix 6.4.1 and grafana 10. i get error Invalid params. Invalid parameter "/": unexpected parameter "user". while connecting to zabbix server.
                      Both Zabbix and Grafana installed in single server or different?

                      Comment

                      • rpav_ia
                        Junior Member
                        • Oct 2023
                        • 2

                        #12
                        I'm receiving the same error when trying to integrate Homeassistant with Zabbix:
                        Code:
                        ERROR (SyncWorker_11) [homeassistant.components.zabbix] Unable to login to the Zabbix API: {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/": unexpected parameter "user".', 'json': "{'jsonrpc': '2.0', 'method': 'user.login', 'params': {'user': 'hass', 'password': '********'}, 'id': '1'}"}
                        Zabbix Server v6.4.8

                        Comment


                        • SIR
                          SIR commented
                          Editing a comment
                          I am dealing with the same problem trying to monitor my Home Assistant installation (Home Assistant Yellow hardware) with my Zabbix 6.4 server. Did you find an answer or solution to this problem? I watched a really good YouTube video from Dmitry Lambert (HOME ASSISTANT and ZABBIX Integration MADE SIMPLE) but the one part that doesn't help is which file or files to edit to correct the problem. Dmitry Lambert was using an installation on Docker and I'm using a VM running Ubuntu so none of the file names or structure match and I'm finding it very difficult to figure out which file or files I need to edit. I find the Home Assistant logs very confusing since they reference many paths and files but none of them exist on my installation so I can only assume these paths and file names are in the configuration or setup and this is the reason they can't be found and don't work. I just need to know where to find these files so I can edit them. I love Linux but it sometimes drives me insane.
                      • Semiadmin
                        Senior Member
                        • Oct 2014
                        • 1625

                        #13
                        In 6.4 a deprecated parameter "user" removed, use "username"

                        Comment


                        • SIR
                          SIR commented
                          Editing a comment
                          Thank you for your reply and answer. Is there any chance you can help further with the name of the file where this change will need to be made? I understand this will need to happen on the Home Assistant installation so this really isn't a Zabbix issue and outside the scope of this forum. I thought I would ask regardless knowing it's a long-shot. Thanks.
                      Working...