How to get all computers information through API calls

tonystonks
New Contributor II

Hi,

 

I am trying to get information of User,  Computer Name, Operating System, Last Inventory Update and Last Check-in through APIs 

Right now, the API I'm dealing with are these 2 below:

https://xxx.jamfcloud.com/api/v1/computers-inventory

https://xxx.jamfcloud.com/uapi/preview/computers 

The problem is they are NOT returning all the computers' details only partially. I even tried with https://xxxx/uapi/preview/computers?page=1&page-size=10000000 or https://xxx/api/v1/computers-inventory?section=GENERAL&page=0&page-size=10000&sort=id%3Aasc.

Do you have any idea what did I miss ? or suggestions to another API calls ?

 

Thank you so much,

2 ACCEPTED SOLUTIONS

stevewood
Honored Contributor II
Honored Contributor II

Ah, yes, that is pretty clear when you read the subject closer... 😎

Short of using a script with a loop to cycle through each computer (which could be a lot depending on # of endpoints), the easiest way to do this is probably with an Advanced Search. Setup the search to display exactly what you want and then call the search via API. Or set it up to be a report that is emailed out.

{{url}}/JSSResource/advancedcomputersearches/id/<id>

View solution in original post

mm2270
Legendary Contributor III

This can be done if you create and save a Computer Advanced search and pull that in the API rather than other resources. The trick is to create a saved advanced search with either no criteria, or criteria that filters out the Macs you are interested in, and more importantly, add the columns of data you're interested in, such as User,  Computer Name, Operating System, Last Inventory Update and Last Check-in like you mention above.

Then in the API you can call that advanced search using the advancedcomputersearches API resource
 https://your.jamf.server/JSSResource/advancedcomputersearches/id/<id>

You'll need to parse the output in your script, but passing the result through xmllint like | xmllint --format - should make the XML structured at least.

Edit: Whoops! I didn't see @stevewood 's post above that basically suggested the same thing. So in short, I agree with him 😉 That's the best option to use when talking about the API.

View solution in original post

9 REPLIES 9

stevewood
Honored Contributor II
Honored Contributor II

You'll need to use the Classic API to get all of the info about a device.

https://developer.jamf.com/jamf-pro/reference/classic-api

The specific endpoints:

https://xxx.jamfcloud.com/JSSResource/computers/id/<id>

https://xxx.jamfcloud.com/JSSResource/computers/serialnumber/<serialnumber>

Either of those will work.

Thanks Steve, I understood those APIs but they are limited to just a single computer per call. My goal is to get all the computer details at once.

stevewood
Honored Contributor II
Honored Contributor II

Ah, yes, that is pretty clear when you read the subject closer... 😎

Short of using a script with a loop to cycle through each computer (which could be a lot depending on # of endpoints), the easiest way to do this is probably with an Advanced Search. Setup the search to display exactly what you want and then call the search via API. Or set it up to be a report that is emailed out.

{{url}}/JSSResource/advancedcomputersearches/id/<id>

mm2270
Legendary Contributor III

This can be done if you create and save a Computer Advanced search and pull that in the API rather than other resources. The trick is to create a saved advanced search with either no criteria, or criteria that filters out the Macs you are interested in, and more importantly, add the columns of data you're interested in, such as User,  Computer Name, Operating System, Last Inventory Update and Last Check-in like you mention above.

Then in the API you can call that advanced search using the advancedcomputersearches API resource
 https://your.jamf.server/JSSResource/advancedcomputersearches/id/<id>

You'll need to parse the output in your script, but passing the result through xmllint like | xmllint --format - should make the XML structured at least.

Edit: Whoops! I didn't see @stevewood 's post above that basically suggested the same thing. So in short, I agree with him 😉 That's the best option to use when talking about the API.

tonystonks
New Contributor II

Thanks guys ! You made my day!

Hope your days are doing great too.

 

Folks,

with the upcoming shutdown of BasicAuth and the classic API,

How can this be accomplished in the new JAMF Pro API?
I'm struggling to find a means to get all this info in one pull.

stevewood
Honored Contributor II
Honored Contributor II

The Classic API is not going away until the Jamf Pro API has full parity. True, Basic Auth is being deprecated this year, but you can simply change over to using token auth in your scripts. Rich Trouton has a great blog post on how to get a bearer token:

https://derflounder.wordpress.com/2022/01/05/updated-script-for-obtaining-checking-and-renewing-bear...

tonystonks
New Contributor II

Hello guys,

As I am shifting away from basic authentication.
For the advancedcomputersearch API, when I have switched to new auth I got the following error.

Unauthorized

The request requires user authentication

You can get technical details here.
Please continue your visit at our home page.

Or should I use the JamfPro API instead of the classic but I was searching for equivalent way I can't find the one as computer-inventory doesn't give the serial numbers for the bulk export (not including those with no prestage assigned) 

Thank you,
Tony

stevewood
Honored Contributor II
Honored Contributor II

Are you using the same user/pass as before but doing bearer token auth, or did you create a new API Client and you are using that? In either case, I would verify that the user/client that you are using has the proper permissions granted for the information you are trying to pull. 

You can also try using Postman, or using curl from Terminal,  with that user/client and see if you are getting a token. Just get a bearer token to verify that you are getting past that part. If you're familiar with Postman you can use the Console in Postman to see the request and response headers and that may help you identify where the issue is. Typically, that type of error indicates the user/client being used does not have the proper permissions.

You can find more information about using Postman, along with the collections, on this page.

You can find the privilege requirements for Classic API here and JPAPI here.