Get a computer's site using API?

howie_isaacks
Valued Contributor II

A few months ago, I was able to use the Jamf API to obtain a computer's room assignment. I need to now get the computer's site. I don't care if I can only obtain the site ID or its actual name. I need this so I can avoid creating a separate installer package for the different regions in my company. I want the install script to first obtain the computer's site assignment and then choose the appropriate customization for each region. I thought this would be similar to getting the room assignment but apparently it's not. Does anyone know the correct way to do this?

1 ACCEPTED SOLUTION

howie_isaacks
Valued Contributor II

Interesting. I have used $EMAIL and $COMPUTERNAME before but not $SITEID. This will be useful. I did figure out how to query the computer's site assignment using the API. One of my coworkers helped me nail it. I added this variable to my script along with a function that handles the Jamf Pro API authentication. This variable returns the site name. I used this variable with a case statement to run the appropriate tagging command after the software is installed. So far, it's working great.

site=$(curl -s -H "Accept: text/xml" -H "Authorization: Bearer ${token}" ${jamfProURL}/JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath 'string (//computer/general/site/name)' -)

 

View solution in original post

2 REPLIES 2

jamf-42
Valued Contributor II

You don't need to use the API.

You can get the site using Configuration Profile Variables, see here:

https://learn.jamf.com/en-US/bundle/jamf-pro-documentation-current/page/Computer_Configuration_Profi...

You can the pull that key using a script or EA

howie_isaacks
Valued Contributor II

Interesting. I have used $EMAIL and $COMPUTERNAME before but not $SITEID. This will be useful. I did figure out how to query the computer's site assignment using the API. One of my coworkers helped me nail it. I added this variable to my script along with a function that handles the Jamf Pro API authentication. This variable returns the site name. I used this variable with a case statement to run the appropriate tagging command after the software is installed. So far, it's working great.

site=$(curl -s -H "Accept: text/xml" -H "Authorization: Bearer ${token}" ${jamfProURL}/JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath 'string (//computer/general/site/name)' -)