Skip to main content
Solved

Get a computer's site using API?

  • September 19, 2024
  • 2 replies
  • 3 views

howie_isaacks
Forum|alt.badge.img+23

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?

Best answer by howie_isaacks

jamf-42 wrote:

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_Profiles.html

You can the pull that key using a script or EA


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

2 replies

jamf-42
Forum|alt.badge.img+17
  • Esteemed Contributor
  • 744 replies
  • September 20, 2024

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_Profiles.html

You can the pull that key using a script or EA


howie_isaacks
Forum|alt.badge.img+23
  • Author
  • Esteemed Contributor
  • 773 replies
  • Answer
  • September 20, 2024
jamf-42 wrote:

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_Profiles.html

You can the pull that key using a script or EA


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)' -)

 


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