iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
👁️‍🗨️

[Zabbix API] Creating a User (7.0)

に公開
2026/02/08

Verified on Ver. 7.0.21
 
Since token issuance, which is essential for handling the ZABBIX API, was touched upon in a previous article, it is omitted here.
https://zenn.dev/iwanorigoro/articles/9bc762e44ee427

Procedure

The general flow is as follows:

1. Obtain an authentication token using the user.login method.
2. Collect the necessary information for user creation.
3. Create a user based on the token obtained in 1 and the information obtained in 2.
4. Invalidate the authentication token using the user.logout method.

 

  1. Obtain an authentication token using the user.login method

    [user.login]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/user/login

    # Obtain an authentication token. Note that params depend on the user used.
    curl -sS \
      --request POST \
      --url 'http://127.0.0.1/zabbix/api_jsonrpc.php' \
      --header 'Content-Type: application/json-rpc' \
      --data '
        {
            "jsonrpc": "2.0",
            "method": "user.login",
            "params": {
                "username": "Admin",
                "password": "zabbix"
            },
            "id": 1
        }' \
      | jq -r 'if .error then .error else .result end'
    

    Response (example)

    0424bd59b807674191e7d77572075f33
    

     

  2. Collect the necessary information for user creation

    [API]
    https://www.zabbix.com/documentation/7.0/en/manual/api
    [Method Reference]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference
    [user.create]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/user/create

     
    First, check the roleid, which is a mandatory parameter for user creation.

    [role.get]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/role/get

    # (Reference) Mandatory parameters for the user object
    # username     Username
    # roleid       User role ID
    

     
    Using the token obtained in step 1, display information for all roles.

    curl -sS \
      --request POST \
      --url 'http://127.0.0.1/zabbix/api_jsonrpc.php' \
      --header 'Authorization: Bearer 0424bd59b807674191e7d77572075f33' \
      --header 'Content-Type: application/json-rpc' \
      --data '
        {
            "jsonrpc": "2.0",
            "method": "role.get",
            "params": {
                "output": "extend"
            },
            "id": 1
        }' \
      | jq -r 'if .error then .error else .result end'
    

    Response

    [
      {
        "roleid": "1",
        "name": "User role",
        "type": "1",
        "readonly": "0"
      },
      {
        "roleid": "2",
        "name": "Admin role",
        "type": "2",
        "readonly": "0"
      },
      {
        "roleid": "3",
        "name": "Super admin role",
        "type": "3",
        "readonly": "1"
      },
      {
        "roleid": "4",
        "name": "Guest role",
        "type": "1",
        "readonly": "0"
      }
    ]
    
    ## type values
    # 1 - User
    # 2 - Admin
    # 3 - Super admin
    
    ## readonly values
    # 0 - No
    # 1 - Yes (Read-only)
    

     
    Since I want to assign a user group to the user being added, I will check the usrgrpid (optional).

    [usergroup.get]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/usergroup/get

    # Get all active user groups
    curl -sS \
      --request POST \
      --url 'http://127.0.0.1/zabbix/api_jsonrpc.php' \
      --header 'Authorization: Bearer 0424bd59b807674191e7d77572075f33' \
      --header 'Content-Type: application/json-rpc' \
      --data '
        {
            "jsonrpc": "2.0",
            "method": "usergroup.get",
            "params": {
                "output": [
                    "usrgrpid",
                    "name"
                ],
                "status": 0
            },
            "id": 1
        }' \
      | jq -r 'if .error then .error else .result end'
    

    Response

    [
      {
        "usrgrpid": "7",
        "name": "Zabbix administrators"
      },
      {
        "usrgrpid": "8",
        "name": "Guests"
      },
      {
        "usrgrpid": "11",
        "name": "Enabled debug mode"
      },
      {
        "usrgrpid": "12",
        "name": "No access to the frontend"
      }
    ]
    

     

  3. Create a user based on the token obtained in 1 and the information obtained in 2

    [user.create]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/user/create

    # Create a "Testman" user as a super admin and assign them to the "Zabbix administrators" group
    curl -sS \
      --request POST \
      --url 'http://127.0.0.1/zabbix/api_jsonrpc.php' \
      --header 'Authorization: Bearer 0424bd59b807674191e7d77572075f33' \
      --header 'Content-Type: application/json-rpc' \
      --data '
        {
            "jsonrpc": "2.0",
            "method": "user.create",
            "params": {
                "username": "Testman",
                "passwd": "Usertest123",
                "roleid": "3",
                "usrgrps": [
                    {
                        "usrgrpid": "7"
                    }
                ]
            },
            "id": 1
        }' \
      | jq -r 'if .error then .error else .result end'
    

    Response

    # Returns userids upon success
    {
      "userids": [
        "3"
      ]
    }
    

     
    Checking the GUI, the user has been created.

     

  4. Invalidate the authentication token using the user.logout method

    [user.logout]
    https://www.zabbix.com/documentation/7.0/en/manual/api/reference/user/logout

    curl -sS \
      --request POST \
      --url 'http://127.0.0.1/zabbix/api_jsonrpc.php' \
      --header 'Authorization: Bearer 0424bd59b807674191e7d77572075f33' \
      --header 'Content-Type: application/json-rpc' \
      --data '
        {
            "jsonrpc": "2.0",
            "method": "user.logout",
            "params": [],
            "id": 1
        }' \
      | jq -r 'if .error then .error else .result end'
    

    Returns true upon successful logout.

    true
    

 
That is all.

Discussion