PDA

View Full Version : API - login not working


StephenKing
03-02-2012, 21:58
Hi,

I'm unsure, if this is really related to Zabbix beta (1.9.8) or whether I'm too stupid (have no 1.8 running).

Login with API is not working. I'm sending this request:

{
"jsonrpc": "2.0",
"method": "user.login",
"params": {
"user": "user",
"password": "password"
},
"auth": null,
"id": 0
}
and zabbix responds with {
"id" : null,
"jsonrpc" : "2.0",
"error" : {
"data" : "Invalid JSON. An error occurred on the server while parsing the JSON text.",
"code" : -32700,
"message" : "Parse error"
}
}

The API changes 1.8 - 2.0 (http://www.zabbix.com/documentation/2.0/manual/appendix/api/changes_1.8_-_2.0) doesn't help me. I just read in the net that user.login replaces user.authenticate.

Do you know, what I'm doing wrong? Is there any other way to debug? Setting Zabbix server log severity to 4 (Debug) didn't help..

Thanks for your response
Steffen

zalex_ua
08-02-2012, 00:51
{
"auth": null,
}

That part could be excess in the request.
See documentation example: http://www.zabbix.com/documentation/...api/user/login

StephenKing
08-02-2012, 07:43
Thanks for your reply, but the "auth" doesn't matter (nothing changes, if it's omitted).

my36
08-02-2012, 19:40
Perhaps try
method: "user.authenticate"

StephenKing
09-02-2012, 20:04
Thanks for your reply. user.authenticate has been renamed to user.login (see Zabbix 2.0 docs (http://www.zabbix.com/documentation/2.0/manual/appendix/api/user/authenticate)). And I tried this, too..

I'm really wondering, what I'm doing wrong. Do I have to enable anything in Zabbix itself?

Thanks for your help
Steffen

my36
09-02-2012, 20:17
user.authenticate works for me in 1.9.8

You also have to have a user with all the permissiones required. I'd try it using
a super admin user with every concievable permission just to make sure it's not
a user permission thing.

StephenKing
10-02-2012, 10:00
Thanks my36.

Yes, both authenticate and login should work according to the docs.

I've just digged into the code. CJSONrpc::_construct($jsonData) is called with empty $jsonData, which causes the parse error. However, I have no clue, why the function is called without data...

Steffen

StephenKing
10-02-2012, 10:06
Ah, okay.. miracle solved.. the body of the CHTTP_request was empty, which was (well..) caused because I've sent it through a GET request.

Of course, it's my own stupidity, but the CocoaRestClient I was using made it too easy to me, to enter a request body, without reminding me that this should be POST then ;)

Now everything works, thanks for trying to help me!