Skip to content

Instantly share code, notes, and snippets.

@vbnin
Created November 14, 2024 20:01
Show Gist options
  • Select an option

  • Save vbnin/1c7c917c97482ab89ac0ad4e2c9f9dd5 to your computer and use it in GitHub Desktop.

Select an option

Save vbnin/1c7c917c97482ab89ac0ad4e2c9f9dd5 to your computer and use it in GitHub Desktop.
Simple Python script showing how to list departments in Jamf Pro using Jamf Pro API and an API client.
### This script will generate a bearer token to Jamf Pro and then list all departments in the Jamf Pro tenant
import requests
url = "https://YOUR_INSTANCE.jamfcloud.com"
client_id = ""
client_secret = ""
# Headers
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
# Data payload
payload = {
"client_id": client_id,
"grant_type": "client_credentials",
"client_secret": client_secret
}
response = requests.post(f"{url}/api/oauth/token", data=payload, headers=headers)
response_data = response.json()
#Get the access token
access_token = response_data["access_token"]
#Use the access token to get the list of departments
departments_url = f"{url}/api/v1/departments"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
# Making the GET request
departments_response = requests.get(departments_url, headers=headers)
departments_data = departments_response.json()
# Print the list of department names
department_names = [department["name"] for department in departments_data["results"]]
print(department_names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment