HTTParty and JSS API

New Contributor

I've been working on a script to either delete computers or unassign the users from them using the JSS API in ruby using httparty.

I've so far been able to make GET commands work for computer info, but I can't seem to find any info on the syntax of a PUT command (using computer serial number).

Anyone out there have any luck getting this to work and looking to share?



New Contributor III

Hi @skoonin,

I just saw this post now, a month later.

I'm not familiar with httparty, but I'm very familiar with using the API via ruby, and have shared my work here:

ruby-jss uses the rest-client gem under the hood, but abstracts all of the GETting and PUTting away from the user.

Using it to delete a computer (after requiring ruby-jss and connecting to the API) would look like this: 1234).delete

and to clear out the username:

computer = 1234)
computer.username = nil

or to clear out all the user & location data:

computer = 1234)

Under the hood, it's building the appropriate XML and passing it in the body of a PUT request to

(well, it always use the jss id, not the serial number, for API calls once it knows the id,but the above URL works the same)

A quick look at the httparty github repo makes me think you can do something like :

# set the headers as needed... 
options = {
  body: '<your xml here>',
  headers: {'Accept' => 'application/json'}
}'/JSSResource/computers/serialnumber/1234', options)

hopefully all that's helpful. Feel free to reach out if you have more questions.

New Contributor

Hey Chris -

Thanks for the response, and I have looked at your JSS gem before and it's super cool. I chose not to use it because I was teaching myself ruby and API stuff. I did managed to get it to work with HTTParty finally.

You're syntax for HTTParty is totally right up there. I ended up using (as an example):

                                body: "<XML>", 
                                headers: { 'Content-Type' => 'text/xml' }, 
                                verify: false, basic_auth: <auth info> )

Now that I understand it, I can look into using your gem in the future if I need it. Thanks again for the reply.