Is there a way to expose "deviceAssignedDate" as a searchable field?

mzukrow
New Contributor

In Settings -> Automated Device Enrollment and via the API call "device-enrollments" you can view "deviceAssignedDate" which is the date each device was enrolled in your orgs JAMF. Assuming DEP machines that should be relatively close to the purchase date of those machines. The date is already in JAMF and it seems silly to have to run an api call to write it back as a searchable field assigned to each machine object. Both ADE and Computer objects have serial numbers so I can't imagine the match would be that hard. 

Seems it would be a way to get that information without needing GSX

Is anyone already using "deviceAssignedDate" via the API and writing back?
Is it already a searchable field and I'm missing it?

2 REPLIES 2

BookMac
Contributor

Did you find a solution? I need exact the same.

BookMac
Contributor

@mzukrow maybe this helps you.

 

#!/bin/bash

# set_ea_deliverydate.sh
# Created on 11.07.2024

# This Scripts sets the extension attribute "M42deliverydate"

# Variables
JAMF_URL="https://xxx.jamfcloud.com"
client_id="xxx"
client_secret="xxx"

API_TOKEN=$(curl --silent --location \
	--request POST "${JAMF_URL}/api/oauth/token" \
	--header "Content-Type: application/x-www-form-urlencoded" \
	--data-urlencode "client_id=${client_id}" \
	--data-urlencode "grant_type=client_credentials" \
	--data-urlencode "client_secret=${client_secret}" | plutil -extract "access_token" raw -o - -)

# get Serial 
SERIAL_NUMBER=$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')
echo "$SERIAL_NUMBER"

# API request
response=$(curl --request GET \
--url "${JAMF_URL}/api/v2/computer-prestages/x/scope" \
--header "Authorization: Bearer ${API_TOKEN}" \
--header 'accept: application/json')


# Check if the API response was successful
if [ $? -eq 0 ]; then
	# Extract serial number and related data
	assignment=$(echo "$response" | sed -n "/\"serialNumber\" *: *\"$SERIAL_NUMBER\"/,/}/{/\"assignmentDate\"/p;}" | sed -n 's/.*"assignmentDate\" *: *\"\([^\"]*\)\".*/\1/p' | head -n 1)
	
	if [ -n "$assignment" ]; then
		echo "Information for serial number $SERIAL_NUMBER:"
		echo "assignmentDate: $assignment"
		
		# Extract only the date part (without time)
		formatted_date=$(echo "$assignment" | cut -d'T' -f1)
		
		# Convert to German date format (DD.MM.YYYY)
		formatted_date_german=$(date -jf "%Y-%m-%d" "$formatted_date" +"%d.%m.%Y")
		
		echo "Date in German format: $formatted_date_german"
	else
		echo "No device found with serial number $SERIAL_NUMBER."
	fi
else
	echo "Error retrieving data from the API."
fi