How the ETag is used for activation in the API

Hello everyone

I am relatively new to using the API
We want to create hosts via the API, which works quite well.
But unfortunately we are not able to activate them via the API.

We use httpie for the API calls as suggested by CheckMK.
But now we get the message during activation:

{
"detail": "ETag didn't match. Expected 2198ee82fff7d885b58f042a50521dff2937601fe0b1a22bb22f46d1dc74b4d6. Probable cause: Object changed by another user.",
"status": 412,
"title": "Precondition failed"
}

Now we ask ourselves where we get this ETag from. The ETag from the creation of the host does not fit:

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 3694
Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' ssh: rdp:; img-src 'self' data: https://*.tile.openstreetmap.org/ ; connect-src 'self' https://crash.checkmk.com/ https://license.checkmk.com/api/verify; frame-ancestors 'self' ; base-uri 'self'; form-action 'self' javascript: 'unsafe-inline'; object-src 'self'; worker-src 'self' blob:
Content-Type: application/json
Date: Tue, 07 Nov 2023 08:09:11 GMT
ETag: "20cdceb46cac77c98753a74eb775d740b12c53990cb67740deac15b61d2085cb"
Keep-Alive: timeout=5, max=100
Permissions-Policy: accelerometer=(), autoplay=(), camera=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), usb=()
Referrer-Policy: origin-when-cross-origin
Server: Apache
X-Checkmk-Edition: cee
X-Checkmk-Version: 2.2.0p12
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
X-Permitted-Cross-Domain-Policies: none
X-XSS-Protection: 1; mode=block

Wo oder wie müssen wir diesen ETag auslesen?
Oder gibt es eine Möglichkeit eine Aktivierung zu machen ohne diesen ETag?

Besten Dank im Voraus für euer Hilfe
Roman

Den ETag für das Aktivieren bekommt man mittels Abfrage von.
/domain-types/activation_run/collections/pending_changes
Im Header sollte dann ein ETag enthalten sein welcher für die Aktivierung verwendet werden kann.

Dank, nun habe ich die richtige Antwort mit dem Header und dem richtigen ETag, bin aber leider einfach nicht fähig diese aus dem Response zu lesen geschweige denn in eine Variabel zu speichern im bash. (Ich weiss es ist eine reine bash Frage, doch ich muss ehrlich gestehen das ich auch im netzt nichts gefunden habe was mich weiterbringen würde. und da HTTPie von CheckMK recomendet wird denke ich das dies sicher schon der einte oder andere gemacht hat.)
Kann mich da jemand in die richtige Richtung schubsen…

Danke im Voraus für euer Hilfe
Roman

Hier das Beispiel gibt den ETag Wert einfach als Variable zurück.

etag=$(
  curl -I \
    --request GET \
    --header "Authorization: Bearer $USERNAME $PASSWORD" \
    --header "Accept: application/json" \
    "$API_URL/domain-types/activation_run/collections/pending_changes"  | grep -Fi etag | sed -r 's/.*"(.*)".*/\1/' )

echo "$etag"

Der Code ist aus den Beispielen von der API Doku und halt etwas erweitert um den ETag zu filtern.

Ok, Danke
Hab mir irgendwie gedacht das es eleganter gehen muss :wink:
Habe es nun mit Python gelöst, was mir auch in Zukunft mehr Optionen offen lässt.

Danke euch für die Hilfe
Gruss
Roman

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.