Skip to content

2023 demo C Connecting

Chris Lasell edited this page Apr 2, 2024 · 3 revisions

Hands On, Real-time Jamf APIs Using ruby-jss

IRB and Connecting to the JSS

Previous           TOC           Next


Jumping into IRB

  • open terminal window
  • Run irb
% irb
irb(main):001:0>

A little about irb

  • 'irb' stands for 'interactive ruby', a real-time ruby interpreter

    • You can type ruby code into it - just like you type bash code into a shell
  • Enter a line of ruby code, it runs and displays the 'return value' after a =>

  • For clarity & easier copy-pasting, in this document:

    • The irb examples will use no prompt
    • Example output will start with a #, so irb will ignore it if you play with this on your own and paste it in

Require ruby-jss

  • In irb, tell ruby that you want to use ruby-jss:
require 'ruby-jss'
# => true
  • Don't worry if you ever require returns false, it just means the thing has already been required

  • Ruby is now aware of a module called Jamf which contains all of the ruby-jss code

    • Note that JSS is a synonym for the Jamf module, you can use them interchangably. A lot of older code uses JSS.
  • While we're requiring, lets do this:

require 'pp'
# => true
  • 'Pretty Print' allows us to examine ruby objects in irb in a more readable format.

  • In this demo, lots of ruby commands I'll paste into irb will end with ;0

    • This makes the irb responses even easier to read - the return value of the line of code is just 0
    • When writing scripts there's no need to do it

Connecting to the API

Jamf.connect 'https://[email protected]/'

# Enter the password for JSS user [email protected]:
# => "[email protected], name: default"
  • By default, you are prompted for the password, but it can be passed in to the 'connect' method also.

  • Here's what we did:

    • The Jamf module has a method (function) connect that activates the default APIConnection object
    • That method takes the parameters needed to connect to the server.
      • You can provide a URL or the indiviual parameters like host:, user:, pw:, port: and more.
    • By default, you are prompted for the password, but it can be passed in to the 'connect' method also.
      • when passing in passwords, beware of security issues
    • If the password is correct, the connection is made, and the connect method returns the server name and the connection name. In this case we are using ruby-jss's 'default' connection, most of the time this is sufficient.

Connection objects in ruby-jss automatically deal with getting a bearer token and using it as required, they will also automatically renew that token under the hood (by default, tokens only last 30 minutes).


Previous           TOC           Next

Clone this wiki locally