-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Pagination available to get the list of mobile devices. #89
Comments
Hi Sonali, The Classic API, used via the 'JSS' module, does not support paging of any kind. The Jamf Pro API, used via the 'Jamf' module does support paging for Mobile Devices, however I haven't had time to do any real work on ruby-jss's Jamf module since the pandemic started, and Mobile Devices via the Jamf Pro API are not yet implemented. BUT - you can still use both APIs together to work with all mobile devices in a paginated way! You can use the lower-level methods of the Jamf::Connection object (Jamf Pro API), to GET paginated data directly from the 'v2/mobile-devices' resource endpoint, specifying the paging. It will return JSON data that will be converted to a Ruby Hash. The hash has a :results key, which contains an Array of Hashes, each with summary data about a device, including its Jamf Pro id. You can then use that to fetch the full JSS::MobileDevice object from the Classic API, and process it as needed. Here is an example of how to do this with ruby-jss: require 'jss'
require 'jamf'
# Classic API Connection:
JSS.api.connect server: 'my.server.host', port: 443, user: 'apiuser' pw: :prompt
# Jamf Pro API Connection:
Jamf.cnx.connect server: 'my.server.host', port: 443, user: 'apiuser' pw: :prompt
# set up the pagination
page_size = 200
page_num = 0
# Fetch the first page of device summariess
paginated_rsrc_path = "v2/mobile-devices?page=#{page_num}&page-size=#{page_size}"
devices = Jamf.cnx.get(paginated_rsrc_path)[:results]
# process the first page and fetch the next page, until there are no more pages
until devices.empty?
puts
puts "## Processing page #{page_num} of #{devices.size} devices"
# process the fetched device summaries
devices.each do |dev_summary|
# if needed, fetch the device object from the Classic API
dev_object = JSS::MobileDevice.fetch id: dev_summary[:id]
puts "Device '#{dev_object.name}' (#{dev_object.id}) running #{dev_object.os_type} #{dev_object.os_version}"
end # devices each
# increment the page number
page_num += 1
# fetch the next page
paginated_rsrc_path = "v2/mobile-devices?page=#{page_num}&page-size=#{page_size}"
devices = Jamf.cnx.get(paginated_rsrc_path)[:results]
end # until devices empty? I hope this helps! I'll try to make some time to get the Jamf module updated soon. Cheers, |
👋 Just sharing how we query mobile devices. This approach won't work if you're looking to get full device objects, but we use this to parse through important data points for reporting purposes... We created an AdvancedMobileDeviceSearch with blank criteria to pull in all mobile devices. We chose this approach because of the ability to include/exclude attributes that you want in the response (through "display" in the Jamf GUI). Then you can just simply call the AdvancedMobileDeviceSearch endpoint and subsequently parse the data however you want:
|
There is "all" method present to get all the device objects but there are no pagination available.
My one of client have 60K mobile devices and "all" method is getting stuck and not working due to heavy records.
I am looking forward to have pagination in "all" to get list of mobile devices.
Please reply soon.
The text was updated successfully, but these errors were encountered: