Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save talkingmoose/09d2ab881b2b7b22d63c7571f4e93e4b to your computer and use it in GitHub Desktop.
Save talkingmoose/09d2ab881b2b7b22d63c7571f4e93e4b to your computer and use it in GitHub Desktop.
Sample Jamf Pro API script to set the value of a mobile device extension attribute "Role" to a value of "Teacher".
#!/bin/bash
# server connection information
URL="https://talkingmoose.jamfcloud.com"
username="api-editor"
password="P@55w0rd"
# provide the Jamf Pro ID of the PreStage Enrollment; look in the URL when viewing the PreStage Enrollment
mobileDeviceID="15"
requestBody='{
"updatedExtensionAttributes": [
{
"name": "Role",
"type": "STRING",
"value": [
"Teacher"
]
}
]
}'
echo requestBody: "$requestBody"
# created base64-encoded credentials
encodedCredentials=$( printf "$username:$password" | /usr/bin/iconv -t ISO-8859-1 | /usr/bin/base64 -i - )
echo encodedCredentials: "$encodedCredentials"
# generate an auth token
authToken=$( /usr/bin/curl "$URL/api/v1/auth/token" \
--silent \
--request POST \
--header "Authorization: Basic $encodedCredentials" )
echo authToken: "$authToken"
# parse authToken for token, omit expiration
token=$( /usr/bin/awk -F \" '/token/{ print $4 }' <<< "$authToken" | /usr/bin/xargs )
echo token: "$token"
# set mobile device EA
/usr/bin/curl "$URL/api/v2/mobile-devices/$mobileDeviceID" \
--silent \
--request PATCH \
--header "Authorization: Bearer $token" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "$requestBody"
# expire the auth token
/usr/bin/curl "$URL/api/v1/auth/invalidate-token" \
--silent \
--request POST \
--header "Authorization: Bearer $token"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment