user.login

Description

string/object user.login(object **parameters**)

This method allows to log in to the API and generate an authentication token.

When using this method, you also need to do user.logout to prevent the generation of a large number of open session records.

Parameters

This method is available to unauthenticated users and must be called without the auth parameter in the JSON-RPC request.

(object) Parameters containing the user name and password.

The method accepts the following parameters.

ParameterTypeDescription
password
(required)
stringUser password.
user
(required)
stringUser name.
userDataflagReturn information about the authenticated user.

Return values

(string/object) If the userData parameter is used, returns an object containing information about the authenticated user.

Additionally to the standard user properties, the following information is returned:

PropertyTypeDescription
debug_modebooleanWhether debug mode is enabled for the user.
gui_accessintegerUser’s authentication method to the frontend.

Refer to the gui_access property of the user group object for a list of possible values.
sessionidstringAuthentication token, which must be used in the following API requests.
useripstringIP address of the user.

If a user has been successfully authenticated after one or more failed attempts, the method will return the current values for the attempt_clock, attempt_failed and attempt_ip properties and then reset them.

If the userData parameter is not used, the method returns an authentication token.

The generated authentication token should be remembered and used in the auth parameter of the following JSON-RPC requests. It is also required when using HTTP authentication.

Examples

Authenticating a user

Authenticate a user.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "user.login",
  4. "params": {
  5. "user": "Admin",
  6. "password": "zabbix"
  7. },
  8. "id": 1
  9. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": "0424bd59b807674191e7d77572075f33",
  4. "id": 1
  5. }

Requesting authenticated user’s information

Authenticate and return additional information about the user.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "user.login",
  4. "params": {
  5. "user": "Admin",
  6. "password": "zabbix",
  7. "userData": true
  8. },
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "userid": "1",
  5. "alias": "Admin",
  6. "name": "Zabbix",
  7. "surname": "Administrator",
  8. "url": "",
  9. "autologin": "1",
  10. "autologout": "0",
  11. "lang": "ru_RU",
  12. "refresh": "0",
  13. "type": "3",
  14. "theme": "default",
  15. "attempt_failed": "0",
  16. "attempt_ip": "127.0.0.1",
  17. "attempt_clock": "1355919038",
  18. "rows_per_page": "50",
  19. "debug_mode": true,
  20. "userip": "127.0.0.1",
  21. "sessionid": "5b56eee8be445e98f0bd42b435736e42",
  22. "gui_access": "0"
  23. },
  24. "id": 1
  25. }

See also

Source

CUser::login() in ui/include/classes/api/services/CUser.php.