Skip to main content
Question

Help with API Restart Script for iPads on JAMF School


Forum|alt.badge.img+1

Hey everyone,

I am wondering if i could get some advice on setting up an API Script for JAMF School that will restart 2 specific iPads at a set time each day. What would be the code and do I have to run it on a Mac? I have seen a few older forums that have restart scripts but i could not get them to work with JAMF School.

I would appreciate any help on this.

3 replies

Forum|alt.badge.img+7
  • Contributor
  • 39 replies
  • February 25, 2022

Jamf provide a description of the api on the zuludesk website: https://api.zuludesk.com/docs/ 

Here is a basic implementation for an api call provided for JavaScript and PHP. But I prefer and use python.

The device restart endpoint is described here https://api.zuludesk.com/docs/#api-Devices-Restart_Device 

 

Now lets get coding...

import requests from requests.auth import HTTPBasicAuth # Settings for authentication against the API endpoint # configured in Jamf-School -> Settings -> API -> Add API Key netwok_id = "123455675332" # Network ID of your API endpoint api_pw = "324JNSDNK29KNKJ239NJKN" # API Password of your Api endpoint authObject = HTTPBasicAuth(network_id, api_pw) url = "https://api.zuludesk.com" # Aquire udid of the device we want to restart # -> if they are always the same you can save these udids and dont need this call path = "/".join((url, "devices")) serialnumber = "GXYZH1292XXX" payload = { "serialnumber": serialnumber } # Serial Number of the device r = requests.get(path, params=payload, auth=authObject) if r.status_code == 200: if len(r.json().get("devices")) > 0: udid = r.json().get("devices")[0].get("UDID") print(f"{serialnumber} -> {udid}") else: print("no device found") exit() # /devices/:udid/restart path = "/".join((url, "devices", udid, "restart")) payload = {"udid": udid, "clearPasscode": "false"} # turn true, if you want to clear passcode first r = requests.post(path, json=payload, auth=authObject) if r.status_code == 200: print(f"{r.json().get('message')} of device {r.json().get('device')}") elif r.status_code == 404: print(f"{r.json().get('message')}") else: print("unknown error occured")

 

I tested this peace of code with my own credentials and a serial number of a known device. and it worked. But you can improve it more. Because it is not really usable at the moment, but this is part of basically python programming at all. 

 

In my own implementation i have encapsulated the Jamf API in a python class and can use it via command-line. 

But with this you can restart a device. (for ure 2 or more device purpose you have to send a request for every device you would like to get, or filter by location or some other stuff mentioned in the documentation. But it is not possible to send a filter like: payload = {"serialnumber": serialnumbers_as_list }  # in this only the last one in the list get returned... not as intuitive - but the api is fast enought to request all devices and filter dem loacally with python to get the list of udids)


Forum|alt.badge.img+1
  • New Contributor
  • 2 replies
  • December 14, 2023

Hi mh-jena,

 

I'm completely new to this, does the URL have to be the API server URL? Also where do I need to put the UDID in. 

 

Thanks so much!

Nile


Forum|alt.badge.img+7
  • Contributor
  • 39 replies
  • December 15, 2023

The example is based on the old api url. You can find your api url in the Jamf School settings -> API.

it should be 

<your_instance_name>.jamfcloud.com/api/

the endpoints need to be appended to the url.

In the example above the udid is part of the url path. That's why it is added in the path:

# /devices/:udid/restart path = "/".join((url, "devices", udid, "restart"))

 

 


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