Skip to content

Instantly share code, notes, and snippets.

@vbnin
Created November 14, 2024 20:19
Show Gist options
  • Select an option

  • Save vbnin/4f3e2ce600b61c533556c5c81590edcf to your computer and use it in GitHub Desktop.

Select an option

Save vbnin/4f3e2ce600b61c533556c5c81590edcf to your computer and use it in GitHub Desktop.
Simple SZH script showing how to list computers in the Jamf Protect macOS Security Portal using GraphQL
#!/bin/zsh
# This script will generate a bearer token for Jamf Protect and list computers in the macOS Security Portal
# Jamf Protect variables
PROTECT_URL='https://YOUR_INSTANCE.protect.jamfcloud.com'
CLIENT_ID=''
CLIENT_SECRET=''
# Generate Bearer Token
tokenCommand=$(curl --request POST \
--silent \
--url "${PROTECT_URL}/token" \
--header 'content-type: application/json' \
--data "{\"client_id\": \"$CLIENT_ID\",
\"password\": \"${CLIENT_SECRET}\"}" \
)
bearerToken=$(jq -r '.access_token' <<< $tokenCommand)
# Create Query data to get all computers' serial number and uuid
read -r -d '' queryData <<EOF
{"query":"{ \
listComputers(input: {}) { \
items { \
serial \
uuid \
} \
pageInfo { \
next \
total \
} \
} \
} \
","variables":{}}
EOF
# Send GraphQL query to Jamf Protect
list_computers_resp=$(curl "${PROTECT_URL}/graphql" \
--silent \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "Authorization: ${bearerToken}" \
--data-binary ${queryData} \
--compressed)
# Read server's answer
echo "$list_computers_resp"
exit 0
@vbnin
Copy link
Author

vbnin commented Nov 14, 2024

This script uses jq to manipulate JSON data, you can install jq using Homebrew or from here: https://jqlang.github.io/jq/download/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment