hey folks!
I Need some help with my Script to trigger API Computer Command "Remote Device Lock"
Purpose: I want a script which requests user input with "Computer Name" , get the Computer Jamf ID (this works!), and afterwords send the Remote Command "Lock Device" with this ID -> at this point I get a Error:
Script result: <html>
<head>
<title>Status page</title>
</head>
<body style="font-family: sans-serif;">
<p style="font-size: 1.2em;font-weight: bold;margin: 1em 0px;">Unauthorized</p>
<p>The request requires user authentication</p>
<p>You can get technical details <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2">here</a>.<br>
Please continue your visit at our <a href="/">home page</a>.
</p>
</body>
</html>
Here are more Informations: I user the API Client&Roles Setting in Jamf, created a API Client with some Priviliges:
"Read Computer Inventory Collection, Update Computers, Read Computers, Create Computers, Send Computer Remote Lock Command"
This is my Script:
Script:
***************************************************************
#!/bin/zsh
read -r -d '' applescriptCode <<'EOF'
set dialogText to text returned of (display dialog "Bitte trage die MacBook-Namen ein." default answer "no input")
return dialogText
EOF
computerName=$(osascript -e "$applescriptCode");
# API login
bearerToken=""
url=https://XXXXXXXX.XXXX:8443
client_id="API Client ID
client_secret="API Client Secret"
# Create Token
token=$(curl --location --request POST "$url/api/oauth/token" \\
--header "Content-Type: application/x-www-form-urlencoded" \\
--data-urlencode "client_id=$client_id" \\
--data-urlencode "grant_type=client_credentials" \\
--data-urlencode "client_name=Test" \\
--data-urlencode "client_secret=$client_secret")
# Catch Token
bearerToken=$(echo "$token" | plutil -extract access_token raw -)
# determine Jamf Pro device id
deviceID=$(curl -s -H "Accept: text/xml" -H "Authorization: Bearer ${bearerToken}" ${url}/JSSResource/computers/name/"$computerName" | xmllint --xpath '/computer/general/id/text()' -)
#echo "$deviceID"
# Execute Device Lock Command
curl -s -H "Accept: application/xml" -H "Authorization: Bearer ${bearerToken}" ${url}/JSSResource/computercommands/command/DeviceLock/passcode/615243/id/"$deviceID" -X POST