Modify An API

New Contributor

Is there any way we can have more parameters added in an API? I mean like,right now JSSResource/computers/subset/basic returns a set of attributes for each computer,what if I need more information ? Thank You,


Contributor III

What information are you after? Could you just modify your call to not be a subset of the data, but the entire computer object to get at the data you want? I do not believe there is a way to change what data is returned when you make a specific call (other than asking JAMF to do so), but hopefully you can adjust your call to get it to return the data you want.

Legendary Contributor III

I'm curious myself what it is that you're looking to get from the API. If you can be more specific, I have a feeling some of us can help you make the needed adjustments to get just the information you're looking for.

Valued Contributor III

You can create Advanced Searches and pull those down with the API, which allows you to customize the data you are retrieving. That sounds like what you might be looking for.

New Contributor

How do you I call the entire computer object?As of now,if I go into the API list the best URL whic cna be all the information in one go is the 'computers/subset/basic' one .It gives me following data :
"computers": [ { "id": 3, "name": "406c8f3ae57b", "managed": true,"username": "z043260 configurator", "model": "Macmini5,2", "department": "", "building": "", "mac_address": "40:6C:8F:3A:E5:7B" "udid": "5A10D86A-ADDE-5C22-AB9D-89D352FF93A7", "serial_number": "C07HV0EXDJD1","report_date_utc": "2015-08-27T01:59:49.226-0500", "report_date_epoch": 1415859138280},.What if I also need warranty data in this list ?

I am trying to load this data into CMDB

Legendary Contributor III

@remyasc Are you asking how to call all data on all computers at once, or all data for one specific computer? These are two different things.

To call all data on one specific Mac

curl -H "Accept: text/xml" -sfku apiusername:apipassword https://your.jss.server:8443/JSSResource/computers/name/{computername}

You can also use other identifiers, like JSS ID, serial number, MAC address, etc. Change the last part of the above accordingly, for ex, using JSS ID it would be:

curl -H "Accept: text/xml" -sfku apiusername:apipassword https://your.jss.server:8443/JSSResource/computers/id/{id}

Does the above help? Also, if you prefer JSON (what you posted in your example above) just remove the header flag in the command (-H "Accept: text/xml") Generally I've seen that under later versions of 9.x JSON is the default.

New Contributor

My requirement is to call all data on all computers at once.The response list doesn't have all the data I am looking for is my concern.

Legendary Contributor III

I'm not aware of a way to do that, at least not without first pulling all JSS computer IDs down, then looping over each one, which, unless you have only a small number of Macs, is going to be painfully slow. If you just do a GET on the base computers object, it only pulls down a list of computer names and their JSS IDs.

The best option is, like @alexjdale mentioned, to create an Advanced saved search in your JSS with the fields you are looking for, then call that Advanced search using the API. When you do this its the equivalent of going into the UI and clicking the "View" button, meaning it does a live Advanced search using the saved criteria and saved display fields.

BTW, can you elaborate on what the requirement is to pull all data on all Macs at once? Why is that needed? Just curious.

New Contributor

This is needed to do load all the Mac data for Asset Management.Can I please get more information on using the advanced search ?

New Contributor

Asset Management team need to have all the data loaded for financial tracking purposes, I am trying to help them get all Mac data

Legendary Contributor III

@remyasc By "all data" do you really mean "all data" as in every single last piece of information on each Mac, or is there a specific set of data items they are looking for? If its the former, then unfortunately, the only way I can think of doing this would be to first gather a list of all Mac JSS IDs, then run a loop function to pull a full record using those IDs by API calls. As I mentioned, this is going to take a long while unless you only have like 100 Macs you're dealing with.
If you can get more specific information on the data the Asset Management team needs, it may be possible to create the Advanced Search in your JSS, add all the columns you can or need, then pull that one report. This is going to be lightyears faster. Not that pulling an advanced search via the API is super quick mind you, but you may be looking at a few minutes, versus possibly hours. Keep in mind there isn't even a way to pull all data on all Macs via the JSS GUI. When you click on Search with no criteria under the Advanced Computer Search section, its pull all Macs but only with the columns of data you've specifically chosen to show in your settings, not everything.

So, you might want to go back to asset management and kindly ask them what it is they need specifically.
If they say they aren't sure, what you can do is go in and create an Advanced search and just check on every single item under all the display columns, pull that and give it to them and see what they say.

Legendary Contributor III

@remyasc In case this is helpful, the following should pull all Macs down (all available API data) into one giant xml file. You would just need to add in your own API information and JSS URL in the variable and let this run, possibly for awhile. As I mentioned, it could take a long time to complete, but then again, maybe not. I always look at this from our perspective, as we have ~10k Macs in our JSS, so doing this here would take a while, plus add some unwanted stress to our JSS.



JSSIDS=$(curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers" -X GET | xmllint --format - | awk -F'>|<' '/<id>/{print $3}' | sort -n)

echo "<computers>" > /tmp/alljssmacdata.xml

while read jssID; do
    curl -H "Accept: text/xml" -sfku "${apiuser}:${apipass}" "${jssurl}/JSSResource/computers/id/${jssID}" -X GET | xmllint --format - | awk '/<computer>/,/</computer>/{print}' >> /tmp/alljssmacdata.xml
done < <(echo "$JSSIDS")

echo "</computers>" >> /tmp/alljssmacdata.xml

mv /tmp/alljssmacdata.xml ~/Desktop

Its very quick and dirty, so could use some adjustments or refinements I'm sure. I let this run on our JSS for just a little over a minute before stopping it and the xml file was already at 3.6 MB.
I still think the saved advanced search will be an easier approach, but that is up to you.

Contributor II

This might belong as a separate thread, but I have a user asking for a single API call to query OS info (eg - how many machines are running 10.10.4?). Using a method like @mm2270's, I can pull from /JSSResource/computers and then dig into <hardware> to get the OS info for a particular machine, but I don't see a way to pull based on "os_version" or "os_build." Advanced Searches are definitely a possibility, but I'd love to do it with a single API call.

New Contributor

I got the list from Asset team and this is what they are looking for :
mac_address ,serial_number,ip_address,username,last_contact_time,make,model,Warranty Data. How do we call saved searches throuhg API,will this mean that I need to make only a single call ?

Valued Contributor II

@remyasc if your computer inventory doesn't change very often, maybe you could create an Advanced Computer Search that includes all computers with those particular items as columns in the report. Then you can simply export the report as either a csv or tab-delimited text file. Then you can just give them that file and you can avoid interfacing with the API at all.

Legendary Contributor III

Hi @remyasc The list posted is all possible through a saved Advanced Computer search. Here's what to do.

In your JSS, go to the "Search Inventory" section in the navbar on the left and click the "[ + ] New" button to start creating a new search.
If you want to pull information on all your Macs, regardless if they are managed or unmanaged, simply leave the main criteria section empty. This is like simply clicking on the "Search" button in the Search Inventory section. It assumes you want data on all computer records.
OTOH, if you want to add in any criteria, you would add them under the Criteria tab, like say, Last Check-in time less than 180 days or whatever, or maybe "Managed" is Managed, to only pull data from managed devices.

Now under the Display tab, click on each of the tabs below, like "Computer", "Hardware", etc and check on the items you are looking to include. Based on the list above from your asset management folks, I would suggest these fields be checked/enabled at a minimum. You may want to include more.

Computer Name
IP Address
Last Check-In <--Is Last Contact Time

MAC Address
Serial Number

User and Location

Whatever fields you need here. There are several, so pick the ones you want. These may only be accurate if you have your JSS linked to a GSX account to pull this data in.

Once this is all set up, you will be able to pull this advanced search report in one of two ways using the API
These show up under 2 different categories in the API. called "advancedcomputersearches" and "computerreports"
The computerreports one may actually be better for your needs since the former one includes some extra data automatically about each Mac, like its JSS ID and such, as well as some tags in the beginning of the xml that have the criteria for the saved search. Not sure if that will add extra work for your asset management team in extracting what they need. Maybe, maybe not. The "computerreports" one is a little simpler, but includes all Mac records that should be in the search and each of those fields. Try them both out and see which is preferable.

curl -H "Accept: text/xml" -sfku apiusername:apipassword -X GET

You can also call it by its ID:

curl -H "Accept: text/xml" -sfku apiusername:apipassword{id} -X GET

New Contributor

Thank you soo much for all the responses .I finally got the report set up as suggested above and this gets successfully pulled in the API .

New Contributor

I am not sure if this is the right way to do but I am reopening the same forum to ask similar question but only this time I need to access software data just like how i accessed hardware data above.I tried taking same approach of getting this data through a report but the report is too heavy that it is timing out ,appreciate any suggestions to work around this.

Legendary Contributor III

@remyasc Can you be more specific on what you mean by "software data"? Do you mean a report on all installed software across the environment? If not, what it is you're looking for?

New Contributor

Yes,all the installed applications for all computers.

New Contributor

A list which contains • application_path
• application_version
• application_name for all the installed applications for all the computers

Valued Contributor II

Bringing this old thread back from the dead! Want to see a customizable "subset" endpoint to return additional data.

My use case is to aid with Site cleanup. I think we have sites with 0 computers, but I don't want to have to run 50+ individual "all computer" searches for each site.

  • Advanced Searches do not include the current site at all, not even as an exportable element.
  • the /sites API endpoint doesn't list all computers in a given site.
  • the /computers/ endpoint is threadbare.
  • the /computers/subset/basic endpoint returns more data, but doesn't include the <site> tag.

Honored Contributor

What data do you need exactly? I see it as there are two sets of data you get with jamf. You get API data (device data) and you get event data (webhooks) and both have different, but some overlapping use cases.