Ad Widget

Collapse

I need help with API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aigo15108
    Junior Member
    • Oct 2019
    • 17

    #1

    I need help with API

    So this is my authenticate method,

    defcreate_session(self):
    self.session = requests.Session()
    self.session.headers = {
    'Content-Type' : 'application/json-rpc'
    }


    defauthenticate (self):

    data = {
    "jsonrpc": "2.0",
    "method": "user.authenticate",
    "params": {
    "user": self.username,
    "password": self.secret
    },
    "id": 1,
    "auth": null
    }

    r =self.session.post(self.url, data= data)

    POST returns this,

    Traceback (most recent call last):
    File "REST.API.py", line 60, in <module>
    main()
    File "REST.API.py", line 56, in main
    restapi.authenticate()
    File "REST.API.py", line 32, in authenticate
    "auth": null
    NameError: name 'null' is not defined

    Any thoughts, ideas on what I am doing wrong?
    thanks in advance,
  • Atsushi
    Senior Member
    • Aug 2013
    • 2028

    #2
    What version of Zabbix are you using? The method user.authenticate is deprecated. Check the API manual and check the necessary parameters.

    Comment

    • aigo15108
      Junior Member
      • Oct 2019
      • 17

      #3
      Originally posted by Atsushi
      What version of Zabbix are you using? The method user.authenticate is deprecated. Check the API manual and check the necessary parameters.

      https://www.zabbix.com/documentation...nce/user/login
      Thanks, I am using version 4.something. I figured what the problem was, as '"auth": null' should not be present in the dataload. This info (that I was referring to) is incorrect; see Authentication section


      Comment

      • Atsushi
        Senior Member
        • Aug 2013
        • 2028

        #4
        The notation on JSON is “null”, but the character “null” may not be defined depending on the programming language. For example, in Python, use "None" to specify that the variable is undefined.
        For API arguments, check the detailed manual of each API. Depending on the API, you may not need to specify auth as an argument.

        Comment

        Working...