Posted on 05-09-2018 01:42 PM
I'm sorry if I've been extremely needy with API help lately. I'm trying to modernize our Mac management and I've made great strides but I find myself in need of just a bit more help on one thing. I have a script which collects the appropriate user location information for Macs via an AppleScript. I have that part working and working well.
Where I could use some help is in my curl syntax to PUT the information into the JSS. Here is my script and I would definitely value any help from someone with better knowledge than I about CURL and the JAMF API. My goal is to run this script via self service. The machine would be able to get it's own serial number. I could use some help though on getting the PUT command right and the xml formatted properly.:
#!/bin/bash
# Enter full URL and credentials to the JSS
apiUser="USERNAME HERE"
apiPass="PASSWORD HERE"
jssUrl="ENTER JSS URL HERE"
serial=`system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'`
buildingName=I HAVE SUCCESSFULLY POPULATED WITH A BUILDING APPLESCRIPT THAT WILL NET ORG APPROPRIATE INFO
roomNumber=I HAVE SUCCESSFULLY POPULATED WITH A ROOM NUMBER APPLESCRIPT THAT WILL NET ORG APPROPRIATE INFO
departmentName=I HAVE SUCCESSFULLY POPULATED WITH A DEPARTMENT SETTING APPLESCRIPT THAT WILL NET ORG APPROPRIATE INFO
position=I HAVE SUCCESSFULLY POPULATED WITH A POSITION SETTING APPLESCRIPT THAT WILL NET ORG APPROPRIATE INFO
curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${apiUser}:${apiPass}" -d "<computer><location><building>$buildingCode</building><position>$position</position><department>$departmentName</department><room>$roomNumber</room></location></computer>" "${jssUrl}/JSSResource/computers/serialnumber/${serial}"
Upon looking at the API documentation, I realize that you can only do a put action on a computer by its ID number. So I will probably need to add a get statement in there before the put operation that gets the ID number of the computer from it’s serial number.
Thank you in advance,
blackholemac
Posted on 05-09-2018 02:38 PM
May I suggest a different approach? Some of the information you're capturing in AppleScript can be applied through a jamf recon
command. And in fact if you've got Jamf Pro setup with an LDAP server you can simply assign the user to computer using the recon command above and it should populate the other location info assuming the user has those LDAP attributes in their AD/LDAP account. It's possible you're aware of this and there's something missing where this doesn't completely do what you want. But hopefully if you weren't aware then this might be a better way to approach the issue you're trying to tackle.
Usage: jamf recon -saveFormTo Saves the contents of the HTTP form to a file The following options allow you to specify inventory information for the computer: -assetTag The asset tag of the computer -endUsername The user name of the primary user -realname The real name of the primary user -email The email address of the primary user -position The position (job title) of the primary user -building The text representation of a building in the jSS -department The text representation of a department in the JSS -phone The phone number of the primary user -room The room that the computer is in -ldapServerID The JSS ID of the LDAP server to which the primary user belongs -userID The user ID of the primary user's account in the LDAP server.
Posted on 05-09-2018 02:39 PM
I have actually tried doing this using the recon command and for issues related to the user approved MDM function in 10.13, I would preferred to do it using the API. That sounds kind of weird but during my initial deployment script I would also like to use this code so the right packages will show up in self-service . When I used sudo jamf recon during deployment, I found that my UAMDM and DEP status was set to “No”. I found that if I set the location information manually in the JSS I’m fine. Hence, I wish to use the API.
Posted on 05-09-2018 04:28 PM
Serial number works to update a record, provided it is unique. Try using -vk (rather than just -k) to get more verbose information about the failure. Are both building and department you're trying to populate already defined in the Jamf Server (Network Organization)?