Skip to main content
Solved

help with an api script


Forum|alt.badge.img+7
  • Valued Contributor
  • 90 replies

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

Best answer by mm2270

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 original
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+16
  • Honored Contributor
  • 1054 replies
  • November 4, 2015

@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/


Forum|alt.badge.img+7
  • Author
  • Valued Contributor
  • 90 replies
  • November 6, 2015

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>


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • November 6, 2015

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

Forum|alt.badge.img+7
  • Author
  • Valued Contributor
  • 90 replies
  • November 6, 2015

worked like a charm. thanks


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings