Smart Computer Group API

itibsolution
New Contributor

Hey JAMFs!
I try to automate the creation of Smart Computer Groups by API (within Powershell) based on the installed Apps criteria.

I'm a bit confused as I don't find anything in the API-documentation fpr smart-computer-group with method POST.

I already have a filtered list of all required groups with app name, path and name for the group.

4 REPLIES 4

Tangentism
Contributor III

The API reference has it under 'Computer Groups' and one of the tags is to define if its a smart group or not:

 

https://developer.jamf.com/jamf-pro/reference/createcomputergroupbyid

itibsolution
New Contributor

Thanks, I didn't find the reference at first, only had the short documentation.
I managed to create the "sync".
My next goal would be a match against the Labels.txt of the installomator, what really isn't that simple as I hoped....

MikePh
New Contributor III
New Contributor III

Depends how automated you're looking to go. Creating a script to create the smart computer groups off a list that you feed the script (whether a file or manually putting it in) wouldn't be too bad. If you want to pull that information from somewhere that may be harder. 

You can't access the ... list of the installed apps criteria, you'd need to for example pick a computer and then use an API call to pull all the apps that it has (assuming it has the full list of apps you'd want)

itibsolution
New Contributor

It works so far:

$clientid = "<clientid>"
$clientsecret = "<cleintsecret>"
$baseURL = "https://<yourcompany>.jamfcloud.com"

$body = @{  client_id = $clientid
            client_secret= $clientsecret
            grant_type='client_credentials'
            }

try {
    $token=Invoke-WebRequest -Uri $baseURL"/oauth/token" -ContentType "application/x-www-form-urlencoded" -Body $body -Method POST
    }
Catch [System.Net.WebException] { $exception = $_.Exception
            $respstream = $exception.Response.GetResponseStream()
            $sr = new-object System.IO.StreamReader $respstream
            $ErrorResult = $sr.ReadToEnd()
            write-host $ErrorResult 
            }
$token = $token.Content | ConvertFrom-Json
$token = $token.access_token


$auth = "Bearer $token"

$AllEntries = Invoke-WebRequest -Uri $baseurl"/api/v1/computers-inventory?section=APPLICATIONS&page=0&page-size=100&sort=general.name%3Aasc" -Headers @{Authorization=$auth} -ContentType "application/json" -Method GET -Verbose
$AllEntries = $AllEntries.Content
$AllEntries = $AllEntries | ConvertFrom-Json


foreach ($Computerentry in $AllEntries.results)
    {
    foreach ($appentry in $Computerentry.applications)
        {
        if ($appentry.path -notlike "/System/*")
            {
            Write-Host $appentry.name
            Write-Host $appentry.path
            $Groupname = "Software - "+$appentry.name.Replace(".app","")
            Write-Host $Groupname
            $xml="
    <computer_group>
	<name>"+$Groupname+"</name>
	<is_smart>true</is_smart>
	<site>
		<id>-1</id>
		<name>None</name>
	</site>
	<criteria>
<size>1</size>
<criterion>
<name>Application Title</name>
<priority>0</priority>
<and_or>and</and_or>
<search_type>is</search_type>
<value>"+$appentry.name+"</value>
<opening_paren>false</opening_paren>
<closing_paren>false</closing_paren>
</criterion>
</criteria>
</computer_group>"

Invoke-WebRequest -uri $baseurl"/JSSResource/computergroups/id/0" -Headers @{Authorization=$auth} -ContentType "application/xml" -body $xml -Method POST

            }
        }
    }

 Challenge now is to match the App-Names to the labels of installomator.