Upgrade to Pro — share decks privately, control downloads, hide ads and more …

API 101: The Building Blocks of Automation

Jamf
November 13, 2019
130

API 101: The Building Blocks of Automation

Jamf

November 13, 2019
Tweet

Transcript

  1. © JAMF Software, LLC API 101: The Building Blocks of

    Automation 9:00–9:45 am UP NEXT
  2. © JAMF Software, LLC API 101: The Building Blocks of

    Automation Presentation agenda: What is an API? But how do I use it? Does Jamf have APIs? That’s cool…so? You mean I can automate all the things?
  3. © JAMF Software, LLC What is an API? (Boring explanation)

    “Application programming (or program) interface: a set of protocols used by programmers to create applications for a specific operating system or to interface between the different modules of an application.” ~Dictionary.com
  4. © JAMF Software, LLC What is an API? Why point

    and click, when you can automate? A point-and-click GUI (graphical user interface) relies on real-time human-interaction every time you want to do something. An API allows you to tell a computer to accomplish the same thing in an automated fashion.
  5. © JAMF Software, LLC What is an API? (Building blocks)

    Terminology Authentication - Credentials needed to securely execute a task Endpoint - Where on the application the data/record is held Call/Request - Initiate communication with the application Response - Data/confirmation of request/action
  6. © JAMF Software, LLC What is an API? (Building blocks)

    Actions/Verbs GET - Retrieve desired information POST - Create a brand new record PUT - Update an existing set of info or record DELETE - Permanently remove info or record
  7. © JAMF Software, LLC But how do I use it?

    Endpoint Authentication Request Server URL Action/ Verb
  8. © JAMF Software, LLC But how do I use it?

    (Request) cURL/curl - Tells the computer to perform the request Flags “-skH”: s - Silent/suppress output k - Proceed without verifying server certs H - Headers, dictates style/type of text to communicate with server (json vs xml)
  9. © JAMF Software, LLC Authentication is required to perform tasks

    via API Flag “-u” tells the curl the next string/data is specifying the credentials needed to perform task Basic authentication or token-based auth But how do I use it? (Auth)
  10. © JAMF Software, LLC Target server URL needed to point

    request to Endpoint (i.e. JSSResource/computers) - Must specify a folder/segment/category of data in order to execute a task or gather data Account used in authentication must have permission to perform tasks within endpoint But how do I use it? (Endpoint)
  11. © JAMF Software, LLC Flag “-X" Tells curl task/verb/action to

    perform GET/POST/PUT/DELETE are the available options If a verb is not specified, it will default to GET But how do I use it? (Action/Verb)
  12. © JAMF Software, LLC 780 px 650 px Max image

    dimensions Does Jamf have an API? Classic API Current API Most endpoints Basic authentication GET JSON/XML Send XML only
  13. © JAMF Software, LLC 780 px 650 px Max image

    dimensions Does Jamf have an API? Jamf Pro API (UAPI) Token-based auth Will eventually mirror Classic API Allows sending of JSON
  14. © JAMF Software, LLC Parsing XML in Bash XML -

    use ‘xmllint --xpath' to isolate specific data. Add ‘text()’ to the end of the path to strip XML elements That’s cool…so? Command Location of data in XML
  15. © JAMF Software, LLC That’s cool…so? Parsing JSON in Python

    Module ‘json’ is required to parse json data Module ‘requests’ is one of many ways to interact with an API
  16. © JAMF Software, LLC That’s cool…so? Goal: Rename computer to

    serial number 1. Get computer’s current name 2. Determine computer’s serial number 3. If needed, adjust computer’s name to serial number
  17. © JAMF Software, LLC Step 1: Get computer’s current name

    by ID Parsing: Get value(s) from response body from an API call xmllint: Tool used to extract XML from response Parsed result: Admin’s Mac Mini That’s cool…so?
  18. © JAMF Software, LLC Step 2: Get computer’s serial number

    Parsed result: C07HH52NDJD2 “Admin’s Mac mini” is not “C07HH52NDJD2” Device name adjustment required That’s cool…so?
  19. © JAMF Software, LLC Step 3: Adjust computer name Flag

    “-d” sends data with PUT/POST request Specify type of data sending “content-type” Jamf Pro accepts XML for PUT/POST/DELETE Device name adjusted to: “C07HH52NDJD2” That’s cool…so?
  20. © JAMF Software, LLC You mean I can automate all

    the things? Automated task examples • Push/Remove restrictions based on time • Automate the generation of complex reports • Enforce branding/naming • Automate onboarding by creating 3rd party SaaS accounts • Automate management commands • Remediate security/compliance issues
  21. © JAMF Software, LLC Tools that use Jamf’s APIs •

    https://github.com/jamf/JamfMigrator - Move records from a Jamf Pro instance to another Jamf Pro instance (i.e. Test to Prod) • https://github.com/mike-levenick/mut - Automate the population of records in your Jamf Pro • https://github.com/jamf/JAWA - Utilize this webhook server to automate your processes based on triggers/actions • https://github.com/kc9wwh/JamfProGroupsScoped - Find out what policies, profiles and apps are scoped to specific groups in your Jamf Pro • https://github.com/rustymyers/jamfMDMTools - Send automated MDM commands to devices
  22. © JAMF Software, LLC Thank you for listening! Give us

    feedback by completing the 2-question session survey in the JNUC 2019 app. UP NEXT Common Pitfalls of Jamf Administration and How to Fix Them 10:15-11:00 am