API PUT URI example?

darms21
New Contributor

I've create a static computer group (TEST_GROUP1) for testing and am trying to add an enrolled computer (COMP1) to it. Can anyone mark up the URI that will accomplish this?

2 REPLIES 2

winningham_2
Contributor

I saw no one answered this and it kept coming up in my search. I eventually found something that worked for me.

curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${apiUsername}:${apiPassword}" -d "<computer><location><username>${lastUser}</username></location></computer>" ${jssServer}/JSSResource/computers/name/$2

This takes my username and password, to write to my JSS, under a computer name that matches what is captured when ran within Casper, to fill out the username within Computers> Location> Username for a given inventory record.

winningham_2
Contributor

A word of note, I am not a coder AT ALL. But I have to do what I am assigned to do and this worked for me. I sure just in case anyone is just behind me in their development as a DevOp/SysMgr

#!/bin/bash


######################### Run this script against a computer name target ##################

#### NOTE: I assume this is running from a JSS policy

# Remember that $2 is reserved for computer name and we will use that here to allow the
#    script to know the username of the computer it is ran against.

# Remember that $3 is reserved for username and we MAY want that information to populate
#       up too so I bring that to our attention. 


## Set your JAMF JSS API paramenters
   apiUsername=$4
    apiPassword=$5
    jssServer=$6
    extensionAttributeName=$7

NOTE: You should probably hardcode the above variables and be sure to set the Last Login extension attribute template too. 

# Use parameter $2, which is the computerName, and use it to search extension_attributes
#   for the lastUser that logged into said computer.
    lastUser=$(curl -s -k -u "${apiUsername}:${apiPassword}" -H "Content-Type: application/xml" -X 'GET' "${jssServer}/JSSResource/computers/name/$2" | xmllint --xpath "( //computer/extension_attributes/extension_attribute/name )[ contains( ., '${extensionAttributeName}' ) ]/../value/text()" - )

# Now that the last user is known, and we have an ID to identify the computer, PUT that 
#   information up to the JSS within User and Location > Username field.
    curl -X PUT -H "Accept: application/xml" -H "Content-type: application/xml" -k -u "${apiUsername}:${apiPassword}" -d "<computer><location><username>$lastUser</username></location></computer>" "${jssServer}/JSSResource/computers/name/$2"

# TEST TEST and more TEST