Last active
January 5, 2022 14:26
-
-
Save rtrouton/4639395aeea34a193443fdb84f1f61cb to your computer and use it in GitHub Desktop.
Example Jamf Pro API call process
This file contains 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
# Get username and password encoded in base64 format and stored as a variable in a script: | |
encodedCredentials=$(printf username_here:password_here | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i -) | |
# Use encoded username and password to request a token with an API call and store the output as a variable in a script: | |
authToken=$(/usr/bin/curl https://server.name.here/api/v1/auth/token --silent --request POST --header "Authorization: Basic ${encodedCredentials}”) | |
# Read the output, extract the token information and store the token information as a variable in a script: | |
api_token=$(/usr/bin/plutil -extract token raw -o - - <<< “$authToken”) | |
# Verify that the token is valid and unexpired by making a separate API call, checking the HTTP status code and storing status code information as a variable in a script: | |
api_authentication_check=$(/usr/bin/curl --write-out %{http_code} --silent --output /dev/null https://server.name.here/api/v1/auth --request GET --header "Authorization: Bearer ${api_token}") | |
#Assuming token is verified to be valid, use the token information to make an API call: | |
/usr/bin/curl --silent -H "Accept: application/xml" --header "Authorization: Bearer ${api_token}" https://server.name.here/JSSResource/packages/id/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment