I get this error–
{
“title”: “Bad Request”,
“status”: 400,
“detail”: “These fields have problems: folder”,
“fields”: {
“folder”: [
“The folder ‘/Windows’ could not be found.”
]
}
}
This is the code I’m trying to use–
#!/bin/bash
HOST_NAME=“mycheckmkserver.mtnam.org”
SITE_NAME=“mysite”
API_URL=“https://$HOST_NAME/$SITE_NAME/check_mk/api/1.0”USERNAME=“automation”
PASSWORD=“mysecret”out=$(
curl
–insecure
–request POST
–write-out “\nxxx-status_code=%{http_code}\n”
–header “Authorization: Bearer $USERNAME $PASSWORD”
–header “Accept: application/json”
–header “Content-Type: application/json”
–data ‘{
“attributes”: {
“ipaddress”: “10.10.1.2”
},
“folder”: “/Windows”,
“host_name”: “agentserver.mtnam.org”
}’
“$API_URL/domain-types/host_config/collections/all”)resp=$( echo “${out}” | grep -v “xxx-status_code” )
code=$( echo “${out}” | awk -F"=" ‘/^xxx-status_code/ {print $2}’)
echo “$resp” | jqif [[ $code -lt 400 ]]; then
echo “OK”
exit 0
else
echo “Request error”
exit 1
fi
Could it be that the automation user doesn’t have access to that folder? Maybe I have that configuration wrong?