Method: JSS::Computer.application_installs

Defined in:
lib/jss/api_object/computer/application_installs.rb

.application_installs(appname, fields: [], version: nil, ids_only: false, api: JSS.api) ⇒ Array<Integer>, ...

Query the JSS for computers with some app installed. An app name is required as the first parameter.

If no other parameters are given, returns a Hash, one key per version of the app. For each version there is an array of Hashes, one Hash for each computer with that version. The sub hashes contain keys for the computer’s identifiers, i.e. :name, :id, :udid, :serial_number, :mac_address.

If one or more inventory fields are provided in the ‘fields’ parameter, each computer’s hash also has keys and values for those fields if they exist in the JSS. These fields are those available in the display options for Advanced Computer Searches (including extention attribute names) and their names are case-sensitive, so ‘Username’, not ‘username’

If a specific version is provided in the ‘version’ parameter, only computers containing that version of the app are returned as an Array of Hashes.

If the ids_only parameter is truthy, an Array of JSS id numbers for computers with this app is returned. In this case the ‘fields’ parameter is ignored, however the ‘version’ parameters is still valid and will restrict the list to those computer ids with that version installed.

This method implements the ‘computerapplications’ API endpoint.

NOTE: To see all the apps installed on a specific computer, fetch the JSS::Computer instance and call its #apps method.

Parameters:

  • appname (String)

    The name of the app to look for, e.g. ‘Transmogrifier.app’

  • fields (String, Array<String>) (defaults to: [])

    Additional ‘inventory fields’ to return with each computer’s data

  • version (String) (defaults to: nil)

    Limit search to a specific version of the app

  • ids_only (Boolean) (defaults to: false)

    Just return an array of the id’s of computers found with this query. Defaults to false

  • api (JSS::APIConnection) (defaults to: JSS.api)

    The API connection to use for the query. default: JSS.api

Returns:

  • (Array<Integer>)

    When ids_only == true, the ids of computers with the app installed (possibly limited to version)

  • (Array<Hash>)

    When version is provided, An Array of Hashes, one for each computer, with keys for identifiers plus any requested fields.

  • (Hash{String => Array<Hash>})

    When no version is provided, a Hash with keys for each version, pointing to an array of Hashes, one for each computer with that version. Each computer’s Hash has keys for identifiers plus any requested fields.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/jss/api_object/computer/application_installs.rb', line 96

def self.application_installs(appname, fields: [], version: nil, ids_only: false, api: JSS.api)
  fields = [fields] unless fields.is_a? Array

  rsrc = "#{COMPUTER_APPLICATIONS_RSRC}/#{CGI.escape appname.to_s}"
  rsrc << "/version/#{CGI.escape version.to_s}" if version
  rsrc << "/inventory/#{CGI.escape fields.join(',')}" unless ids_only || fields.empty?

  result = api.get_rsrc(rsrc)[:computer_applications]

  return result[:unique_computers].map { |c| c[:id] } if ids_only

  if version.nil?
    hash_by_version = {}
    result[:versions].each { |v| hash_by_version[v[:number]] = v[:computers] }
    return hash_by_version
  end

  result[:versions].first[:computers]
end