Hey - so I've learned how to use what I think we are now supposed to call the legacy Rest API in various useful ways. One I have been working on is a powershell (I have my reasons) which emails the total results from various existing "reports" aka inventory searches or advanced computer searches in JAMF to specific recipients. For example, say I have two reports on "Disk Encryption Compliance" and "Security Agent Compliance" - I use the API to search out those two reports by name like so:
[xml]$JAPInfo = Invoke-WebRequest -Uri https://jss:8443/computerreports/name/$reportname -Credential $secureCreds #-Verbose
I then have some logic to loop through my list of desired report names and get counts of members in each report and relate that as percentages of the number of Macs in my fleet or other criterion, then email that as a simple table:
![sample outlook report view]
But what I would really put the icing on the cake for this report would be to pull down another report, "All non-compliant devices" as a csv file, very much like I do manually now by clicking on that saved computer search, clicking view, clicking report, then clicking download report and getting a nice CSV. Alternately, I could construct this as a Smart Computer Group, then view it, then click export, select the csv radio button, click next, and computers then next again to download the csv of that report.
Is there a way to get the actual report csv via the API? I know I can compile it somewhat from the requests I'm invoking above, but that XML doesn't seem to contain everything that I've set to display in the report (for example, my compliance criteria usually determined through extension attributes, and in my "all non-compliant devices" report I'd want to show all the different extension attributes I look at. The canned report does this nicely to a csv, whereas I'd be stuck converting the json or xml output from the API to csv to then dump to a file that I then attach back into the email report. I'd much prefer if there were something like:
$ReportCSV = Invoke-WebRequest -Uri https://jss:8443/computerreports/name/$reportname/export-as-csv -Credential $secureCreds #-Verbose $ReportCSV | export-csv \path omy oncompliant.csv Send-MailMessage @EmailParameters -Body ($Html1 + $Html2 + $privacydisclaimer) -BodyAsHTML -Attachments \path omy oncompliant.csv
This isn't exactly what you're asking, but in the latest releases of Jamf Pro, the ability to schedule a report to be pulled and emailed out to a list of recipients is built into the product. Just in case you weren't aware of that I thought I'd mention it, because it's possible it could fill the need here.
In case it doesn't, there is a script out there built by someone at Jamf that can pull saved advanced reports via the API and convert them into csv format. I'll see if I can locate the specific thread where it was mentioned and links to the script posted and post back here with it if I manage to find it again. Keep in mind it was a bash based script or maybe it was python. I don't exactly remember, but I do know it was not in Powershell, so whether it could be converted to Powershell I couldn't say.
I also worked on something like this some years ago now. I eventually abandoned the work because the specific API resource I was using as the basis of the entire thing was labeled as being deprecated in a future release, and the new API resource URL was harder to work with to get the exact results I was looking for.