Posted on 08-31-2022 08:20 AM
Trying to build a API (I hope this is correct) to get the following information from Jamf / Computer. Where can I find the API Variable list.
Mac Address
Computer Name
Model
Serial Number
Last Check-in
Last Enrollment
Operating System
Department
Position
Full Name
Username
I have 3 of the variables already that I created a long time ago but now can't find the site / document with the list.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>department</key>
<string>$DEPARTMENTNAME</string>
<key>email</key>
<string>$EMAIL</string>
<key>fullname</key>
<string>$FULLNAME</string>
<key>username</key>
<string>$USERNAME</string>
</dict>
</plist>
Solved! Go to Solution.
Posted on 08-31-2022 08:36 AM
So are you trying to use the API to pull that list of information from a computer record? I do not believe there is any variable list for the API. The only variables I am aware of are those used for Configuration Profiles, and other areas:
https://docs.jamf.com/10.28.0/jamf-pro/administrator-guide/Computer_Configuration_Profiles.html
For the API, if you're sending a call to gather those items, you would use xpath or maybe xmllint to pull just the data you want out of the XML returned from an API call. For example, this snippet would be used in Bash/Zsh to pull the serial number of a device from the returned XML:
JSS_ID=$(curl -H "Accept: text/xml" -sfku "${apiUser}:${apiPass}" "${jpsURL}/JSSResource/computers/serialnumber/${serial}/subset/general" | xpath /computer/general/id | awk -F'>|<' '{print $3}')
So if you wanted to pull the values you have listed, you'd need to do something similar for each one.
I'm sure there's someone out there that has a more elegant way to pull the info out of the XML.
08-31-2022 09:09 AM - edited 08-31-2022 09:10 AM
Yep, pretty sure Steve is right that you're looking for configuration profile payload variables. Lists would be here:
macOS: https://jamf.it/macprofile
iOS: https://jamf.it/iosprofile
Posted on 08-31-2022 08:32 AM
I think you're looking for https://your.jamf.server.com/api
From there you can access the Classic or new Jamf Pro API documentation. Hopefully that's helpful.
Posted on 08-31-2022 08:36 AM
So are you trying to use the API to pull that list of information from a computer record? I do not believe there is any variable list for the API. The only variables I am aware of are those used for Configuration Profiles, and other areas:
https://docs.jamf.com/10.28.0/jamf-pro/administrator-guide/Computer_Configuration_Profiles.html
For the API, if you're sending a call to gather those items, you would use xpath or maybe xmllint to pull just the data you want out of the XML returned from an API call. For example, this snippet would be used in Bash/Zsh to pull the serial number of a device from the returned XML:
JSS_ID=$(curl -H "Accept: text/xml" -sfku "${apiUser}:${apiPass}" "${jpsURL}/JSSResource/computers/serialnumber/${serial}/subset/general" | xpath /computer/general/id | awk -F'>|<' '{print $3}')
So if you wanted to pull the values you have listed, you'd need to do something similar for each one.
I'm sure there's someone out there that has a more elegant way to pull the info out of the XML.
08-31-2022 08:53 AM - edited 08-31-2022 08:54 AM
I guess it's not API but what I am trying to do is pull the required fields from Jamf and store the info in a PList file on the workstation (that it is related to).
then when need by script, I use this command to get the information
userDept=$( /usr/bin/defaults read "Library/Managed Preferences/com.company.userinfo.plist" department)
08-31-2022 09:09 AM - edited 08-31-2022 09:10 AM
Yep, pretty sure Steve is right that you're looking for configuration profile payload variables. Lists would be here:
macOS: https://jamf.it/macprofile
iOS: https://jamf.it/iosprofile
Posted on 08-31-2022 09:17 AM
Here's an example script that would do what you are looking for. You can duplicate the example of pulling the department and storing it to get the other items you want to store.
****!!!!!!***** HOWEVER, I would strongly suggest you to reconsider doing this. The use of credentials in scripts is not recommended as it is a security risk. The credentials for the API account are available in clear text on the device. It's better to find a different way to do what you are attempting to do.
#!/bin/zsh
#set -x
xpath() {
# the xpath tool changes in Big Sur
if [[ $(sw_vers -buildVersion) > "20A" ]]; then
/usr/bin/xpath -e "$@"
else
/usr/bin/xpath "$@"
fi
}
apiUser='' #### put in your API user
apiPass='' #### put in your API user password
jpsURL="" #### put in your JPS URL
local_plist="/tmp/com.test.plist" ### change to where you want the plist stored and named
serial=$(system_profiler SPHardwareDataType | awk '/Serial\ Number\ \(system\)/ {print $NF}');
## get xml of computer
comp_xml=$(curl -H "Accept: text/xml" -sfku "${apiUser}:${apiPass}" "${jpsURL}/JSSResource/computers/serialnumber/${serial}")
# grab the department and store in our local plist
dept=$( echo $comp_xml | xpath /computer/location/department | awk -F'>|<' '{print $3}')
defaults write "$local_plist" Department "$dept"