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