Add roles to use API using HTTPIE

CMK version: 2.0.0p6 (CRE)
OS version: Centos 7.9

I am following API Example as given in documentation

#!/bin/bash
HOST_NAME="localhost"
SITE_NAME="site"
API_URL="http://$HOST_NAME/$SITE_NAME/check_mk/api/1.0"

USERNAME="automation"
PASSWORD="test123"

http PUT "$API_URL/objects/user_config/user" \
    --json
    "Authorization: Bearer $USERNAME $PASSWORD" \
    "Accept: application/json" \
    'If-Match:a20ceacf346041dc' \
    'Content-Type:application/json' \
    fullname='Mathias Kettner' \
    auth_option='{'auth_type': 'password', 'password': 'password'}' \
    enforce_password_change='True' \
    disable_login='False' \
    contact_options='{'email': 'user@example.com'}' \
    pager_address='' \
    idle_timeout='{}' \
    roles='['user']' \
    authorized_sites='['heute']' \
    contactgroups='['all']' \
    disable_notifications='{'disabled': False}' \
    language='en' \

actual code:

#!/bin/bash
HOST_NAME="localhost"
SITE_NAME="site"
API_URL="http://$HOST_NAME//$SITE_NAME/check_mk/api/1.0"

USERNAME="USER"
PASSWORD="PASSWD"

http --verbose --verify=no --follow --timeout 3600 PUT "$API_URL/objects/user_config/user" \
    "Authorization: Bearer $USERNAME $PASSWORD" \
    "Accept: application/json" \
    roles='['user']'

The API call runs fine however i am not seeing any change in the role, i have simplified the call to change role for now. Any idea what i may be missing ?

Output:

    "idle_timeout": {
            "option": "global"
        },
        "pager_address": "",
        "roles": []
    }

The role in both examples are “user” - Not sure I understand

@Anders “user” is one of the default roles , i am trying to add few roles for selective group of people however the API doesnt seem to update the user profile

Ok, it looks like the roles are empty, have you tried curl?
Even if checkmk provides examples they do not always work and the new RestAPI makes changes all the time and some functions just don’t work despite they are “stable releases”

I tried using postman API application, let me try some more.

@Anders I have managed to get the API working, i am seeing it allows only built in enum values to be assigned and custom roles are not accepted.

Could you confirm if this is a design or bug ?

image

That seems to be a bug, if you already HAVE created “ctrl_admin”.
I can’t replicate it as we are using LDAP for our users

Hi,
this is fixed with Werk 14365 in 2.0.0p26 or 2.1.0p3.
With an update to either version this should work as intended.

Cheers Jeronimo

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.