Jamf pro API basics

user-mJctiRnnQS
New Contributor

I am new to Jamf Pro API. Would like to discuss few points.

1) I have registered trail in Jamf Pro. But not yet received email , even i checked in Junk folder.
2) To access/execute Jamf Pro API, i can run from RestClient tool from any OperationSystem right ?
3) How to move computer into a static group through API details ?

3 REPLIES 3

talkingmoose
Moderator
Moderator
  1. Reach out to Jamf Support at support@jamf.com. I'm not sure that's the appropriate address for you to use, but someone should be able to respond.

  2. Here's the API documentation. This is a REST API, so any tools that support REST should work.
    https://www.jamf.com/developers/apis/jamf-pro/overview/

  3. I have an example here.
    https://gist.github.com/talkingmoose/ad57503c09fac1ba73768c32b187284b

nelsoni
Contributor III

I got it working and have it fairly automated, only variable you have to change is the Static group ID number.

#!/bin/sh

#API login info
apiuser=Username
apipass=Password
jamfProURL="https://ORGName.jamfcloud.com"

#Grab serial number and OS Version of computer
SerialNumber=$(system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}')
macOSVersion=$(sw_vers -productVersion)

#update group with Group ID you want
GroupID="[ID Number]"
apiURL="JSSResource/computergroups/id/${GroupID}"

#Check macOS Major
CheckIt=$(echo $macOSVersion | cut -d . -f 1)

#Add Computer to group based on macOS Version
if [[ "$CheckIt" == "11" ]]
    then
        #macOS 11 update to xpath requires "-e" in front of xml query
        GroupName=$(curl -H "Accept: application/xml" -sfku "${apiuser}:${apipass}" -X GET "${jamfProURL}/${apiURL}" | xpath -e '/computer_group/name/text()' 2>/dev/null)

    else

        GroupName=$(curl -H "Accept: application/xml" -sfku "${apiuser}:${apipass}" -X GET "${jamfProURL}/${apiURL}" | xpath '/computer_group/name/text()' 2>/dev/null)

fi

#XML header stuff
xmlHeader="<?xml version="1.0" encoding="UTF-8"?>"

#API command to add the serial number to the Static Group
apiData="<computer_group><id>${GroupID}</id><name>${GroupName}</name><computer_additions><computer><serial_number>$SerialNumber</serial_number></computer></computer_additions></computer_group>"

#Mix it all together
curl -sSkiu ${apiuser}:${apipass} "${jamfProURL}/${apiURL}" 
    -H "Content-Type: text/xml" 
    -d "${xmlHeader}${apiData}" 
    -X PUT  > /dev/null

#Run an Inventory Update
sudo /usr/local/jamf/bin/jamf recon

sleep 5

exit 0

Caspernewbie202
New Contributor II

Hi All

Looking for some help - assistance- moral support :)
Unlike many enterprises - we have had a hard time getting JIM integrated in order to get ldap working for JAMF cloud--- Mostly software allocations
Instead of going yet another manual route due to security restrictions - and lack of ldap in my jamf instance- im looking to injecting this via an API.
Obviously would need to be complex- and doable in python - but not sure where to start with jamf API
To give you a mental picture
An python job running internally to fetch ldap attributes of xx macOS users (easily done)
Feed the info to the API of jamf- not sure which reference to use to populate such in a put command as its pretty customized
This is mostly for "memberof" assertion of logged in user/machine owner to be fed into an extension attribute- and use the extension attributes (complete list of ldap groups associated to user-- parsed) and use that to scope software.

Anyone doing something similar in the community without the availability of ldap but making something or fabricating something in aiding them for software allocation (licensed software, ect)

Please share your feels- thoughts- on how to go about doing this!

Thanks so much!!!!