help with an api script

jchurch
Contributor II

we have been having some issues where the configuration profile for the wifi settings are getting corrupted and iOS devices have to have the profile removed and re-applied. its a simple enough thing to work around. I've set the wifi profile to exclude a certain group. all one has to do is connect to an open wifi network, (i use our guest network) add the problem device to the group to remove the profile, wait a couple seconds, and then remove it from the group to have the profile re-apply. simple enough, but something a non-jss-admin user is capable of.

my goal is to put a script into self service that simply prompts for a serial number, then automatically adds and then removes it from the group.

i haven't used the api before and am not sure where to start

thanks

Joe

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

You could try using an Applescript call to ask for input, but its not always 100% reliable when run from policies out of the JSS. Generally, when run from Self Service they should work. Its more an issue when run from a recurring trigger for example.

Example:

#!/bin/sh

SERIAL=$(/usr/bin/osascript << EOF
tell application "System Events"
try
set Serial to text returned of (display dialog "Enter a serial number" buttons {"Cancel", "Enter"} default button 2 default answer "")
end try
end tell
EOF)

if [ "$SERIAL" != "" ]; then
    echo "User input serial: $SERIAL"
else
   echo "User canceled. Exiting"
   exit 0
fi

View solution in original post

4 REPLIES 4

gachowski
Valued Contributor II

@jchurch

These are good starting points

https://jamfnation.jamfsoftware.com/discussion.html?id=10188

http://macbrained.org/the-jss-rest-api-for-everyone/

https://bryson3gps.wordpress.com/the-unofficial-jss-api-docs/

jchurch
Contributor II

so i got my script to mostly work. I'm using an extension attribute and a smart group. it works fine if the serial number is in the script, i want it to popup and ask the user to enter the serial number. here's what i have so far.

#!/bin/sh


YourAPIUsername="username"
YourAPIPassword="password"
jssurl="jssurl"
serialnumber="<manual input>"
FIX="/path/to/FIX.xml"
DONE="/path/to/DONE.xml"


curl -k -v -u $YourAPIUsername:$YourAPIPassword $jssurl/JSSResource/mobiledevices/serialnumber/$serialnumber/subset/extensionattributes -T "$FIX" -X PUT
sleep 3
curl -k -v -u $YourAPIUsername:$YourAPIPassword $jssurl/JSSResource/mobiledevices/serialnumber/$serialnumber/subset/extensionattributes -T "$DONE" -X PUT

these are my xml files:

DONE.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mobile_device>
<extension_attributes> <attribute> <name>WiFi Fix</name> <type>String</type> <value>DONE</value> </attribute>
</extension_attributes>
</mobile_device>

FIX.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mobile_device>
<extension_attributes> <attribute> <name>WiFi Fix</name> <type>String</type> <value>FIX</value> </attribute>
</extension_attributes>
</mobile_device>

mm2270
Legendary Contributor III

You could try using an Applescript call to ask for input, but its not always 100% reliable when run from policies out of the JSS. Generally, when run from Self Service they should work. Its more an issue when run from a recurring trigger for example.

Example:

#!/bin/sh

SERIAL=$(/usr/bin/osascript << EOF
tell application "System Events"
try
set Serial to text returned of (display dialog "Enter a serial number" buttons {"Cancel", "Enter"} default button 2 default answer "")
end try
end tell
EOF)

if [ "$SERIAL" != "" ]; then
    echo "User input serial: $SERIAL"
else
   echo "User canceled. Exiting"
   exit 0
fi

jchurch
Contributor II

worked like a charm. thanks