get jssID of iPad from serial number via api

jchurch
Contributor II

ok. so here's me situation. i need for a teacher to be able to go into self service on their laptop and run a policy that asks for a student iPad serial number and then does an update inventory on that device.

it looks like i can use the api to do the update inventory, but only by device id.

i need the line/lines of code to put in a serial number and get a device id

thanks

Joe

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

I'd like to help, and I'm pretty sure I could, except that we don't manage any iOS devices with our Casper install here. Not even one. So I have no API record to go on to see how to go about scripting it to get that data.
What I can post is some basic code to pull the JSS ID for a Mac though. I'm thinking this could be easily modified to work with mobile devices. Maybe as simple as changing the JSS Resource, but you'll have to test that, or someone else can confirm what needs to be changed.

#!/bin/bash

apiuser="apiuser"
apipass="apipass"
jssurl="https://your-jss-server.com:8443"

serial_number=$(/usr/bin/osascript << EOF
set SERIALNUM to text returned of (display dialog "Enter the Serial Number of the iOS device" buttons {"OK","Cancel"} default button 1 default answer "")
EOF)

SER=$(echo "$serial_number")

JSS_ID=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/serialnumber/${SER}/subset/general" | xpath /computer/general/id[1] | awk -F'>|<' '{print $3}')

echo "Device JSS ID is: $JSS_ID"

I also don't know how well the Applescript call will work when run from Self Service. It may depend on the OS its running on, so you may have to make adjustments to that, or use another tool like cocoaDialog, etc.

View solution in original post

2 REPLIES 2

mm2270
Legendary Contributor III

I'd like to help, and I'm pretty sure I could, except that we don't manage any iOS devices with our Casper install here. Not even one. So I have no API record to go on to see how to go about scripting it to get that data.
What I can post is some basic code to pull the JSS ID for a Mac though. I'm thinking this could be easily modified to work with mobile devices. Maybe as simple as changing the JSS Resource, but you'll have to test that, or someone else can confirm what needs to be changed.

#!/bin/bash

apiuser="apiuser"
apipass="apipass"
jssurl="https://your-jss-server.com:8443"

serial_number=$(/usr/bin/osascript << EOF
set SERIALNUM to text returned of (display dialog "Enter the Serial Number of the iOS device" buttons {"OK","Cancel"} default button 1 default answer "")
EOF)

SER=$(echo "$serial_number")

JSS_ID=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/serialnumber/${SER}/subset/general" | xpath /computer/general/id[1] | awk -F'>|<' '{print $3}')

echo "Device JSS ID is: $JSS_ID"

I also don't know how well the Applescript call will work when run from Self Service. It may depend on the OS its running on, so you may have to make adjustments to that, or use another tool like cocoaDialog, etc.

jchurch
Contributor II

WORKED thanks. the apple script call works fine

i had to massage your command just a little to adapt for mobile devices. this is the line i used

JSS_ID=$(curl -H "Accept: text/xml" -sfku "$YourAPIUsername:$YourAPIPassword" "$jssurl/JSSResource/mobiledevices/serialnumber/$SERIAL/subset/general" | xpath /mobile_device/general/id[1] | awk -F'>|<' '{print $3}')

echo "Device JSS ID is: $JSS_ID"

before even try and figure it out... any hints on the proper syntax for triggering the update inventory?