Created
November 14, 2024 20:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script uses jq to manipulate JSON data, you can install jq using Homebrew or from here: https://jqlang.github.io/jq/download/