Accepting changes (after creating Host) not possible via CheckMK API

CMK version: 2.2.0p5

I created a new Host, via the CheckMK API (in PowerShell) with the subsequent commands:

$API_headers = @{
        "Authorization"="Bearer $user $password"
        "Accept" = "application/json"
        "ContentType"= "application/json" 
}

$API_body = @{
        "folder"="/"
        "host_name"=$Hostname
} | ConvertTo-Json

Invoke-RestMethod -Headers $API_headers -Body $API_body  -Method Post -Uri "$API_URL/domain-types/host_config/collections/all"

This works as expected. After that I wanna accept the changes via the API.

I tried executing the discovery check via the subsequent command:

Invoke-RestMethod -Headers $API_headers -Method Post -Uri "$API_URL/domain-types/activation_run/actions/activate-changes/invoke"

This gives me the subsequent Error Message:

"title": "Precondition required", "status": 428, "detail": "If-Match header required for this operation. See documentation."

I looked into the documentation and there it states, that I need the objects E-Tag header. If I try to read out the information of the host with the subsequent command, I can’t seem to find an E-Tag Header:

Invoke-RestMethod -Headers $API_headers -Method Get -Uri "$API_URL/domain-types/service/collections/all?host_name=$HostName"

Does anybody have the same problem or know how to fix this problem? Is there maybe an alternative way to execute the accepting of the changes or could it have something to do with my CheckMK Version?

1 Like

I think you need to insert

"If-Match" = "*"

inside your header lines.
For the activation of changes you don’t need an specific etag this is only important if you change an object (host/rules and so on).

1 Like

Hello, Andreas,
Here is my request, that produced Etag error

out=$(
  curl --request POST \
    --write-out "\nxxx-status_code=%{http_code}\n" \
    --header "Authorization: Bearer $uname $secret" \
    --header "Accept: application/json" \
    --header "Content-Type: application/json" \
    --header "If-Match: \"*\"" \
    --data "{
          \"force_foreign_changes\": true,
          \"redirect\": false,
          \"sites\": [
            \"$site\"
          ]
        }" \
    "$API_URL/domain-types/activation_run/actions/activate-changes/invoke")

And in response I am getting this

out='{"title": "Precondition failed", "status": 412, "detail": "ETag didn'\''t match. Expected 8e0bd90a3a1b1df8a48ea4ac1a27f0652cbc22efafc966be26e64f9bd7302c7c. Probable cause: Object changed by another user."}

What am I doing wrong?

Hi,

Did you ever find out to fix this issue? I’m seeing the same behavior, also this header is not mentioned at The Checkmk REST API .

Well, for anyone is stuck on this. The following fixed it for me. I make an api call to : api/1.0/domain-types/activation_run/collections/pending_changes and get the Etag header value from there and use it in my activation POST.

The document is a little bit vague about this, because it reads like: You can use everything you want basicly. But it should match and is important.

Could you please share your part of code related to extracting ETAG from the request to the